#15776 - doudou - Thu Jan 29, 2004 10:25 pm
I have some trouble with sprites that goes out of screen in the left and top (left -> x negative, top -> y negative). If i use a 16x16 sprite, i don't want it to be off when x < 0 or y < 0 but when x < -16 or y < -16. Does this problem occur often or the problem is in my sprite_manager ?
#15780 - DekuTree64 - Fri Jan 30, 2004 12:07 am
Are you ANDing your positions with 511 for x and 255 for y? If not, a negative will fill the upper part of the attribute with 1's, which will make a mess of things. For example, X position 510 will place the upper left corner 2 pixels off the left of the screen. Since -2 in binary is 1111111111111110, then if you AND with 511, which is 111111111, you get 111111110, which is 510, so it works. The positions aren't exactly signed numbers, because 128 for a Y coordinate is still on the screen, even though it's the same binary value as an 8-bit -128. They wrap around in the same way though, so anAND is all you need.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku