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 > 2D Sprite Problems

#125270 - Codeninja - Thu Apr 12, 2007 2:31 pm

Okay I've spent all day looking around for a solution to what I'm guessing is a pretty easy and pretty n00by bug to fix but I've given in to the shame of making a thread to receive some help to my problem. Anyones the problem is the sprite just doesn't display correctly.

The picture linked here should pretty much explain the problem and allow anyone who has a solution to help me.

Code:
   public:
      void UpdateOAM(SpriteEntry * spriteEntry){
         DC_FlushAll();
         dmaCopy(spriteEntry,OAM,128 * sizeof(SpriteEntry));
      };
      void InitOAM(SpriteEntry * spriteEntry, SpriteRotation * spriteRotation){
         // For all 128 Sprites on the DS, disable and clear any attributes they
         // might have.  This prevents any garbage from being displayed and gives
         // us a clean slate to work with.
         for(int i=0;i<128;i++){
            spriteEntry[i].attribute[0] = ATTR0_DISABLED;
            spriteEntry[i].attribute[1] = 0;
            spriteEntry[i].attribute[2] = 0;
         }
         // For all 32 Possible sprite rotations, set them to default values
         for(int i = 0; i < 32; i++){
            spriteRotation[i].hdx = 256;
            spriteRotation[i].hdy = 0;
            spriteRotation[i].vdx = 0;
            spriteRotation[i].vdy = 256;
         }
         this->UpdateOAM(spriteEntry);
      };
      void MoveSprite(SpriteEntry * spriteEntry, u16 x, u16 y){
         spriteEntry->attribute[1] &= 0xFE00;
         spriteEntry->attribute[1] |= (x & 0x01FF);

         spriteEntry->attribute[0] &= 0xFF00;
         spriteEntry->attribute[0] |= (y & 0x00FF);
      };

      void RotateSprite(SpriteRotation * spriteRotation, u16 angle){
         s16 s = -SIN[angle & 0x1FF] >> 4;
         s16 c = COS[angle & 0x1FF] >> 4;

         spriteRotation->hdx = c;
         spriteRotation->hdy = -s;
         spriteRotation->vdx = s;
         spriteRotation->vdy = c;
      };
      void InitSprites(SpriteEntry * spriteEntry, SpriteRotation * spriteRotation){
         // init OAM
         this->InitOAM(spriteEntry, spriteRotation);

         Coordinate position;
         position.x = SCREEN_WIDTH/2-64;
         position.y = SCREEN_HEIGHT/2-64;

         // create the ship sprite
         int spriteZeroID = 64;

         spriteEntry[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | ((int)position.y & 0x00FF);//able to rotscale
         spriteEntry[0].attribute[1] = ATTR1_ROTDATA(0) | ATTR1_SIZE_64 | ((int)position.x & 0x01FF); // size: 64 x 64
         spriteEntry[0].attribute[2] = spriteZeroID;

         RotateSprite(&spriteRotation[0],0);

         dmaCopy(master, (uint16 *)SPRITE_PALETTE, (uint32)master_size);
         dmaCopy(ship, &SPRITE_GFX[spriteZeroID * 16], (uint32)ship_size);

         // update the OAM
         this->UpdateOAM(spriteEntry);
      };
   };


The code is as above - is there something wrong with my code or with my creating of the image file? Because I'm not entirely sure how I'm supposed to use gfx2gba... I used it with the following line for the sprite

gfx2gba -t8 ship.pcx

and used the master.pal and ship.raw files I got from that in my little test and it didn't turn out too good. As you can tell.


Any help would be appreciated, thank you very much for your time.

#125299 - Stuk - Thu Apr 12, 2007 4:21 pm

What should the sprite look like? I recently had a sprite problem: http://forum.gbadev.org/viewtopic.php?t=12931.

However I am also quite new to DS coding, so I can't really offer much more help :)