gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > sprite scrolling[solved]

#168819 - Tommmie - Wed May 27, 2009 8:32 pm

ok, so I was coding on my game and i came across this problem: when i position a sprite on x = 300 for example i can't view it at the beginning. how can i scroll the sprite system? i mean that sprites placed on x = 0 wille disappear at a specific moment and the sprite at x = 300 will be visible?

Last edited by Tommmie on Thu May 28, 2009 3:26 pm; edited 1 time in total

#168828 - Emmanuel - Thu May 28, 2009 2:38 am

Tommmie wrote:
ok, so I was coding on my game and i came across this problem: when i position a sprite on x = 300 for example i can't view it at the beginning. how can i scroll the sprite system? i mean that sprites placed on x = 0 wille disappear at a specific moment and the sprite at x = 300 will be visible?


I set the sprite in positions relative to the screen always, and store the position in the stage in an object's variable. And so the sprite doesn't wrap weirdly, when the difference indicates the sprite is out of the screen, I just set it in a safe position 256,193 for example.

If the viewpoint is at the bg scrolled 200 pixels, you would set X in the oam for
x = 0 to 0 - 200
x= 300 to 300-200

#168833 - gauauu - Thu May 28, 2009 2:54 pm

To elaborate on what Emmanuel said:

The position of your sprite is always it's real screen position, not scrolled. So for your in-game characters, you should store their world position separately, and then each frame, update the sprite positions based on where the world is scrolled to.

If the character is offscreen, you'd want to make sure not to show a sprite for it. (Either hide or disable the sprite, or don't have a sprite allocated for that character).

In general, you really need to have a separate layer for logical characters than for hardware sprites, to deal with things like this.

#168835 - Tommmie - Thu May 28, 2009 3:25 pm

thanks i got it(easy, how could i be so stupid?). fast replies also, thanks gauauu and emmanuel