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.

DS development > Sprite placements seem to be about 16 pixels off x and y?

#93631 - TheRain - Thu Jul 20, 2006 7:01 am

So... I'm trying to figure out why this is... but my sprites seem to be consistantly off in placement by about 16 pixels both on the x and y... give or take 2 pixels.... here's my code
Code:

newbutton.x=0;
newbutton.y=0;

sprites[spritesInitialized].attribute[0] = ATTR0_BMP | ATTR0_ROTSCALE_DOUBLE | (newbutton.y);
sprites[spritesInitialized].attribute[1] = ATTR1_SIZE_32 | (newbutton.x); 
sprites[spritesInitialized].attribute[2] = ATTR2_ALPHA(1)| ((normalx*4)+(normaly*128));

#93632 - Cearn - Thu Jul 20, 2006 7:59 am

ATTR0_ROTSCALE_DOUBLE doubles the normal canvas for objects, but the object's position is still the top-left corner. As a result, the center seems offset by half the object size.

#93761 - TheRain - Fri Jul 21, 2006 2:04 am

Ah cool... that makes much (some) sense I guess.

Can someone tell me how to apply rotational attributes to a single sprite entry?? The only example I've seen sets the same rotational attribute for all sprites by doing
Code:

  SpriteEntry sprites[128];
  pSpriteRotation spriteRotations = (pSpriteRotation)sprites;

and then later


   spriteRotations[0].hdx=256;
   spriteRotations[0].hdy=0;
   spriteRotations[0].vdx=0;
   spriteRotations[0].vdy=256;


Also, what is .hdx, .hdy,.vdx, .vdy anyway?

#93804 - Cearn - Fri Jul 21, 2006 11:06 am

TheRain wrote:
Ah cool... that makes much (some) sense I guess.

Can someone tell me how to apply rotational attributes to a single sprite entry?? The only example I've seen sets the same rotational attribute for all sprites by doing
Code:

  SpriteEntry sprites[128];
  pSpriteRotation spriteRotations = (pSpriteRotation)sprites;

and then later


   spriteRotations[0].hdx=256;
   spriteRotations[0].hdy=0;
   spriteRotations[0].vdx=0;
   spriteRotations[0].vdy=256;


Also, what is .hdx, .hdy,.vdx, .vdy anyway?


tonc:affine matrix. You really might consider starting with GBA stuff to learn the ropes; the tools, emus and documentation are much more mature than DS stuff.

hdx, hdy, vdx, vdy form the same matrix as pa-pd. hdx=pa, vdy=pd. MAthematically it'd be better if hdy and vdx were pc and pb, respectively, as the columns of P are the vectors (in which case h and v would correspond to u and v), but I think hdy and vdx are actually pb and pc. Contrary to what you might think from the name, hdy does not affect the sprite in the y-direction.

#93853 - TheRain - Fri Jul 21, 2006 5:45 pm

Thanks man... Actually, that is my last graphics question... i've got all the 2d functionality I can think of having now. Thanks a bunch!