Some sprite are disappearing and I have no idea why.

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Pawel
Posts: 5
Joined: Tue Jan 18, 2022 7:38 pm

Some sprite are disappearing and I have no idea why.

Post by Pawel »

It's hard to explain so here is a short video;

https://youtu.be/uDHGcpPKvag

Some sprites are disappearing when the player's y position is the same as the position of those sprites.
Some other sprites are disappearing when the bullet appears on the same y coordinate but only if the bullet is moving horizontally.

I have no idea what could cause it and no idea where to start looking.
I am hoping someone will point me in the right direction.
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Some sprite are disappearing and I have no idea why.

Post by Banshaku »

If everything on the screen is built with sprite then this is your issue. The nes only allows a maximum of 8 sprites per line so once this occurs, the sprites with higher indexes are dropped first.
Drag
Posts: 1615
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: Some sprite are disappearing and I have no idea why.

Post by Drag »

Yep, each row of pixels on the screen can only have 8 sprites on it. Therefore, things that don't move (such as walls and other obstacles) need to be put in the background instead of the sprites. This is a good time to learn about how the nametables and the attribute tables work, if you're following a tutorial.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Some sprite are disappearing and I have no idea why.

Post by unregistered »

Pawel, have you every played the NES’s Super Dodgeball? The ball flickers at times bc of the NES 8-sprites-per-scanline limit.

The entire field is displayed with nametables as Drag mentioned. The ball flickers bc the game is constantly changing the Sprite order… without the Sprite order being changed every frame, the ball (or whatever is last) would disappear for a while; thus, the game wouldn’t be playable. :)
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Some sprite are disappearing and I have no idea why.

Post by tokumaru »

In your other thread I mentioned sprite flickering vs. sprite dropout. What you're seeing here is sprite dropout. The tank uses lower-numbered OAM slots, so it gets higher priority over the other sprites, and when the PPU finds more than 8 sprites in a scanline, it only draws the 8 with highest priorities.

To get sprite flicker instead of sprite dropout, you have to cycle the sprite priorities over time, so that different sprites are dropped each frame, meaning that none of them is invisible 100% of the time.

But even with sprite cycling, you're not supposed to draw everything in your garage using sprites. Like others said, non-moving structures like brick blocks should be drawn on the background (name tables).
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Some sprite are disappearing and I have no idea why.

Post by Pokun »

Some games doesn't handle sprite dropout very well and you are killed by invisible lasers as a result. I remember the MSX1 version of Gradius being annoyingly notable for this (MSX1 has a maximum of 4 sprites per scanline compared to the 8 sprites/scanline of the NES). Most games flickers the sprites though. Techniques that Increases the sprites/scanline limit like this is called sprite multiplexing.

I made a ROM long ago that demonstrates the problem/feature and another one that uses the simplest form of sprite multiplexing (cycling the OAM) to solve it. They are both included here:
obj_over.zip
Sprite dropout and multiplexing demos.
(4.88 KiB) Downloaded 43 times
The first ROM has 9 sprites and the 9th sprites has slivers of it disappear at every scanline shared by more than 8 sprites.
The second ROM cycles the sprite slots in OAM which causes the first and last sprite to flicker on each scanline shared by more than 8 sprites.
Note that the position of the sprites on the screen doesn't matter. I've ordered them left to right in the demos, but it's the position in OAM that matters. In the OAM cycling demo, the sprites alternates OAM positions every frame, so the numbers written on the sprites does not necessarily match with their OAM slot numbers anymore.
Post Reply