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.

Beginners > movesprites before or atfer wait for vsync?

#33684 - jenswa - Thu Jan 06, 2005 8:44 pm

The question simple,

should i move my sprites before waitforvsync or should i move them after the waitforvsync is over?

Like this

Code:
Movesprites();
WaitForVsync();


or

Code:
WaitForVsync();
Movesprites();


These code is within the main loop of my program.

thanks
Jenswa[/code]
_________________
It seems this wasn't lost after all.

#33685 - DekuTree64 - Thu Jan 06, 2005 8:50 pm

Usually you want to do all your movement and collision detection BEFORE VBlank, and only set up the OAM entries inside VBlank.
Most people make an array of OAM entries in RAM and fill that out during the sprite updating (outside VBlank), and only DMA that to the hardware OAM in VBlank. Faster overall, since you don't have to go back through your list of sprites a second time to set up the OAMs.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#33686 - Wriggler - Thu Jan 06, 2005 9:03 pm

Yep, so your code will look like this:

Code:

moveSprites();
waitForVBlank();
copyOAM();


That's the way to go, do all of your internal calculations in moveSprites(), then just do a quick memory copy inside of copyOAM(). I like to think of it as double buffering sprites, so you update your "sprite backbuffer" during moveSprites(), and then swap your buffers in copyOAM(). Not the most technically correct explanation, but it helped me understand it!

Ben

#33689 - jenswa - Thu Jan 06, 2005 9:32 pm

Thanks guys.

I always seem to forget this and then later on have some weird sprites not moving correctly.

Jenswa
_________________
It seems this wasn't lost after all.