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 > Boundary problems with rotation

#74561 - CyberSlag5k - Sun Mar 05, 2006 11:41 pm

I'm experiencing this problem with my sprites. I have one that I move around the screen, but when it hits the left boundary of the screen, it turns into a solid block of yellow (the sprite itself is predominantly yellow) and stays that way. If the sprite moves beyond the upper boundary it disappears completely, never to return.

Kinda weird. If I disable rotation and move it beyond the left portion of the screen, it flips upside down, which I think is normal, only it stays that way when it gets moved back out it stays flipped upside down.

I can post whatever code is appropriate, though I'm not really doing anything outlandish. I update my OAM entries every tick, my rotation data is pointing to my array of OAM entries, and the position is updated each tick as such:

Code:

sprites[0].attribute0 = sprites[0].attribute0 & 0xFF00;
sprites[0].attribute0 = sprites[0].attribute0 | y;
   
sprites[0].attribute1 = sprites[0].attribute1 & 0xFE00;
sprites[0].attribute1 = sprites[0].attribute1 | x;


The way I'm setting things up is also probly relavent, so here ya go:

Code:

   SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

   
   initializeSprites();

   for(u16 i = 0; i < 256; i++)
      OBJPaletteMem[i] = palette[i];
   
   sprites[0].attribute0 = COLOR_256 | SQUARE | ROTATION_FLAG | y;
   sprites[0].attribute1 = SIZE_64 | ROTDATA(0) | x;
   sprites[0].attribute2 = 0;
   
   sprites[1].attribute0 = COLOR_256 | SQUARE | 60;
   sprites[1].attribute1 = SIZE_64 | 80 ;
   sprites[1].attribute2 = 0;


Pretty tutorialish, eh? Anyway, if anyone has any ideas as to what's going on, it would be appreciated.

Thanks!
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#74565 - tepples - Mon Mar 06, 2006 12:04 am

CyberSlag5k wrote:
I'm experiencing this problem with my sprites. I have one that I move around the screen, but when it hits the left boundary of the screen, it turns into a solid block of yellow (the sprite itself is predominantly yellow) and stays that way.

This question is answered in the FAQ:
Q: Why do my sprites become corrupt when I move them off the top or the left side of the screen?

Solution:
Code:
sprites[0].attribute0 = sprites[0].attribute0 & 0xFF00;
sprites[0].attribute0 = sprites[0].attribute0 | (y & 0x00FF);
   
sprites[0].attribute1 = sprites[0].attribute1 & 0xFE00;
sprites[0].attribute1 = sprites[0].attribute1 | (x & 0x01FF);

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#74566 - nmain - Mon Mar 06, 2006 12:04 am

if your x and y variables are signed, the switch to negative will be setting bits (by 2's complement representation) that you don't want set. use a bitmask to shave off extra bits of the x and y when you set the attribute to them.

edit: foilt again!


Last edited by nmain on Mon Mar 06, 2006 4:16 am; edited 1 time in total

#74567 - CyberSlag5k - Mon Mar 06, 2006 12:27 am

Silly me. Thank you.
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...