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 > Off-screen sprites

#674 - Psyk - Thu Jan 09, 2003 5:51 pm

I have a sprite that is stationary on the map but not on the screen. In other words the sprite moves across the screen as the background moves. Everything is fine when it goes off the screen to the right or off the bottom (x>240 and/or y>160) but the problem is when the x or y coordinate goes below 0. I know it cant actually go below 0 and that's the problem, I want the sprite to be displayed half off the screen on the left or off the top. Does anyone know any good way of doing this? The only thing I can think of is put a huge border around it as another background that the sprite can go under until it can't be seen and can then be moved off the screen.

#679 - Lord Graga - Thu Jan 09, 2003 6:31 pm

I think you are using the wrong kind of variable for the position, some kinds of variables can't go to less than 0.

#680 - Splam - Thu Jan 09, 2003 6:33 pm

Just make them negative values, you can't do this obviously by using signed short or whatever because x has 9 bits and y has 8 and they're both part of a 16bit register, but (in say y) if you just make them 0-however far off the screen u want them to be & 255 they should appear partially off the screen. so like (0-10)&255 kind of thing will make the sprite 10 pixels off the top of the screen.. &511 for x btw.

#692 - Psyk - Thu Jan 09, 2003 7:48 pm

Ok works fine now. Thanks for the help