#109932 - gs2phateon - Thu Nov 23, 2006 6:16 am
How do you clip a sprite so that it's partially shown on the screen? The project I'm working on uses 64x64 sprites that have to be able to enter/exit the screen fairly easily, so it would probably look funny if they just disappeared altogether if they got near the edge of the screen.
#109934 - DiscoStew - Thu Nov 23, 2006 6:23 am
Sprites get clipped automatically. When moving them off the screen towards the right/bottom, no adjustments need to be made. However, when going off the screen towards the left/top, because you can't use negative numbers, you either have to add 512 (for the X coor) to your negative number, and/or 256 (the Y coor) to it.
_________________
DS - It's all about DiscoStew
#109945 - Cearn - Thu Nov 23, 2006 10:43 am
You can use negative numbers, actually. The x and y fields in the object attributes are effectively 9-bit and 8-bit signed integers, so additions re not required. Just be sure to always mask the other bits off.
#109955 - tepples - Thu Nov 23, 2006 4:58 pm
Both DiscoStew and Cearn are right, but which conceptualization is easier for a novice to understand?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#109962 - Cearn - Thu Nov 23, 2006 5:23 pm
That depends on the novice I guess :P
To make the coordinates fit into the allotted 9 and 8 bits, masking them off with 0x1FF or 0xFF is the Right Thing to do anyway. This makes adding 512 or 256 for negative numbers (which adds extra logic to the process and breaks the number line) an irrelevant distraction.
#109978 - gs2phateon - Thu Nov 23, 2006 10:21 pm
Ok, thanks for the help with clipping the sprite off the left side of the screen, that makes sense to me.