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.

Coding > Placing a Sprite Slightly Off-Screen

#8303 - dchartier - Mon Jul 07, 2003 8:34 pm

Hello all,

I'm trying to get an 8 x 8 sprite positioned such that its leftmost side is off-screen and the rightmost side is on-screen (i.e., part of the sprite is left of the screen's left-hand side). I tried doing so by setting the sprite's x-coordinate to 512 - 1 = 511, which I thought would work because of a vague blurb in the CowBite FAQ. Unfortunately, rather than going off-screen, the sprite disappears. I encounter the same problem when I try to make a sprite disappear off the top of the screen.

Can anyone tell me how I can make the sprite appear partially on-screen?

BTW: I used the BoyCottAdvance emulator if that makes any difference. I didn't try any others.

Thanks for your help!

Doug

#8308 - Wanderer - Tue Jul 08, 2003 12:51 am

Hi,

that should work, it's always worked for me (on Boycott Advance too)... if Irecall correctly its covered in the tutorials at: http://www.mdh165.pwp.blueyonder.co.uk/docstuts/docstuts.htm which were what I started with (they're C based in PDF format)

I'd try making sure the sprite works as expected when fully on the screen, and make sure you don't overflow the x value to greater than 511 or y>255 as that might cause problems.


Wanderer.

#8341 - dchartier - Tue Jul 08, 2003 7:36 pm

Silly me. I calculated the x-coordinate by:

newx = x % 512;

which, to my surprise, returns -1 for x == -1 rather than 511 as I had expected. Changing the code to newx = x + 512 fixed the problem.

I learn something new about C every day!

Thanks for your help.