Hi,
I was implementing sprite priority and testing Balloon Fight and found that the sprite for the Balloon in the title screen is behind the background. So it didn't show up in my emulator.
So I implemented transparency for backgrounds the same as I had in sprites. ie anything at palette addresses 3F00, 3F04, 3F08, 3F12 are considered transparent and show what is at palette 0. This showed the balloon, but the background changed from black to grey. Infact for the 3 different games I tested all the backgrounds went grey. This seems a logical outcome as the color at palette index 0 (3F00) is grey.
Am I on the right track here?
The last part of my getBackgroundPixel() method
And my drawPixel() method:
I was implementing sprite priority and testing Balloon Fight and found that the sprite for the Balloon in the title screen is behind the background. So it didn't show up in my emulator.
So I implemented transparency for backgrounds the same as I had in sprites. ie anything at palette addresses 3F00, 3F04, 3F08, 3F12 are considered transparent and show what is at palette 0. This showed the balloon, but the background changed from black to grey. Infact for the 3 different games I tested all the backgrounds went grey. This seems a logical outcome as the color at palette index 0 (3F00) is grey.
Am I on the right track here?
The last part of my getBackgroundPixel() method
Code:
let attributeIndex = UInt8((shiftRegisterPaletteA >> shift) & 0x03)
let address = UInt16(pattern | attributeIndex << 2)
// Every 4th palette index maps to background color
if address % 4 == 0
{
return 0
}
let paletteIndex = mapper!.readByte( atLocation:UInt16(0x3F00) + address)
return Int(paletteIndex)
}
let address = UInt16(pattern | attributeIndex << 2)
// Every 4th palette index maps to background color
if address % 4 == 0
{
return 0
}
let paletteIndex = mapper!.readByte( atLocation:UInt16(0x3F00) + address)
return Int(paletteIndex)
}
And my drawPixel() method:
Code:
private func drawPixel()
{
guard case 1...256 = cycle else { return }
let x = cycle - 1
let y = scanline
let backgroundPixel = getBackgroundPixel()
let (sprite, spritePixel, spriteZero) = getSpritePixel()
var pixel = 0
if spritePixel != 0 && backgroundPixel == 0
{
pixel = spritePixel
}
else if spritePixel == 0 && backgroundPixel != 0
{
pixel = backgroundPixel
}
else
{
if spriteZero == true
{
spriteZeroHit = true
}
pixel = sprite?.behind == true ? backgroundPixel : spritePixel
}
let color = Palette.color( atIndex:pixel)
pixelBuffer.setPixel( x:x, y:y, r:color[0], g:color[1], b:color[2])
}
{
guard case 1...256 = cycle else { return }
let x = cycle - 1
let y = scanline
let backgroundPixel = getBackgroundPixel()
let (sprite, spritePixel, spriteZero) = getSpritePixel()
var pixel = 0
if spritePixel != 0 && backgroundPixel == 0
{
pixel = spritePixel
}
else if spritePixel == 0 && backgroundPixel != 0
{
pixel = backgroundPixel
}
else
{
if spriteZero == true
{
spriteZeroHit = true
}
pixel = sprite?.behind == true ? backgroundPixel : spritePixel
}
let color = Palette.color( atIndex:pixel)
pixelBuffer.setPixel( x:x, y:y, r:color[0], g:color[1], b:color[2])
}
Attachment:
Attachment:
Attachment: