#27220 - mr_square - Wed Oct 06, 2004 11:25 pm
Hi all. This:
Code: |
sprites[0].attribute0 = COLOR_256 | SQUARE | 50;
sprites[0].attribute1 = SIZE_64 | 0;
sprites[0].attribute2 = 0; |
displays my sprite as I'd expect it to, but this:
Code: |
sprites[0].attribute0 = COLOR_256 | SQUARE | 50;
sprites[0].attribute1 = SIZE_64 | -1;
sprites[0].attribute2 = 0;
|
(or any negative number in attribute 1's X slot) displays the sprite at the far left of the screen but flipped vertically. Any idea whats going on?
#27224 - sajiimori - Thu Oct 07, 2004 12:09 am
As a 16 bit value, -1 is 0xFFFF, so you're setting all the bits in that attribute to 1.
#27227 - getch - Thu Oct 07, 2004 12:28 am
Dont have reference data with me, but I'm pretty sure for negative x value you put in (512 + x). So to display a sprite at x coordinate -1 you set it to 511.
For y values its (256 + y) I think.
#27232 - Abscissa - Thu Oct 07, 2004 2:10 am
getch wrote: |
Dont have reference data with me, but I'm pretty sure for negative x value you put in (512 + x). So to display a sprite at x coordinate -1 you set it to 511.
For y values its (256 + y) I think. |
That's correct. What you can also do that might make more sense is to mask out the bits you don't want to be setting instead of adding 512 or 256. So like this:
Code: |
sprites[0].attribute1 = SIZE_64 | (-1 & 0x01FF);
//or
sprites[0].attribute1 = SIZE_64 | (X_Value & 0x01FF); |
And for Y just use 0x00FF instead of 0x01FF. This is because the x value is the low 9 bits, and the y value is the low 8 bits. When you do -1, that's really 0xFFFF, and you need to chop off those extra bits at the high end since those do other things (like vertical flip).
Correction: The mask for the low 9 bits of an integer is 0x01FF, not 0x007F. -- tepples
#27233 - Abscissa - Thu Oct 07, 2004 2:21 am
BTW, if by "setting sprite offscreen" you mean *completely* offscreen, then an x value of -1 won't do it, it'll just be partially offscreen (one column of pixels of it).
#27243 - mr_square - Thu Oct 07, 2004 11:43 am
Great - thanks guys, got it sorted.
The effect I was after was a little intro movie whereby my character runs in from offscreen, pulls a pose, and then runs off again. Looks great now :)