#50034 - justinGBA - Thu Aug 04, 2005 6:39 pm
I'm haveing some trouble with setting up a sprite class, the problem lies in what i believe is the passing of the array of data. Without the information being classed up it all works fine, so if anyone can take at look at this code, and maybe point out what im doing wrong...
Here are some of my defines i use...
here is the working block of code...
So that chunk of code works fine, no issues at all. So i know my DMAFastCopy function works. So here is the sprite class code that doesnt.
Sprite Header...
Sprite Cpp...
Guess:
It appears of if it is copying data over, but for some reason it seams to copy in data missing a chunk of the sprite... Just guessing... The first method displays the airplane fine, colorkeyed and all. The class, displays the arplane with the bottom half f the tale on the top half of the sprite rect, and the top half of the plane on the bottom half of the sprite rect. However it is colorkeyed properly.
Here are some of my defines i use...
Code: |
//define object attribute memory state address #define SpriteMem ((unsigned short*)0x7000000) //define object attribute memory image address #define SpriteData ((unsigned short*)0x6010000) //define object attribute memory palette address #define SpritePaletteMemoryPointer ((unsigned short*)0x5000200) #define OBJ_MAP_2D 0x0 #define OBJ_MAP_1D 0x40 #define OBJ_ENABLE 0x1000 //attribute0 stuff #define ROTATION_FLAG 0x100 #define SIZE_DOUBLE 0x200 #define MODE_NORMAL 0x0 #define MODE_TRANSPARENT 0x400 #define MODE_WINDOWED 0x800 #define MOSAIC 0x1000 #define COLOR_16 0x0000 #define COLOR_256 0x2000 #define SQUARE 0x0 #define TALL 0x4000 #define WIDE 0x8000 //attribute1 stuff #define ROTDATA(n) ((n) << 9) #define HORIZONTAL_FLIP 0x1000 #define VERTICAL_FLIP 0x2000 #define SIZE_8 0x0 #define SIZE_16 0x4000 #define SIZE_32 0x8000 #define SIZE_64 0xC000 //Attribute2 stuff #define PRIORITY(n) ((n) << 10) #define PALETTE(n) ((n) << 12) typedef struct tagSprite { unsigned short attribute0; unsigned short attribute1; unsigned short attribute2; unsigned short attribute3; }Sprite,*pSprite; |
here is the working block of code...
Code: |
//format of data... //const unsigned short airplaneData[] ={ ... } DMAFastCopy((void*)airplanePalette, (void*)SpritePaletteMemoryPointer, 256, DMA_16NOW); //copy the tiles into sprite tile mem DMAFastCopy((void*)airplaneData, (void*)SpriteData, sizeof(airplaneData), DMA_32NOW); Sprite mySprite; int sY = 126; int sX = 240 / 2 - 16; int sVelX = 1; int anim = 0; mySprite.attribute2 = anim*32; //tileIndex mySprite.attribute0 = COLOR_256 | sY; //color mode, y pos mySprite.attribute1 = SIZE_32 | sX; //spriteSize, x pos DMAFastCopy((void*)&mySprite, (void*)SpriteMem, sizeof(mySprite), DMA_32NOW); |
So that chunk of code works fine, no issues at all. So i know my DMAFastCopy function works. So here is the sprite class code that doesnt.
Sprite Header...
Code: |
#ifndef GBASPRITE_H #define GBASPRITE_H #include "gba.h" class gbaSprite { public: gbaSprite(const unsigned short spriteTiles[], int width, int height, int totalFrames); ~gbaSprite(); void Activate(); void UpdateOAM(); void LoadAnimationStates(char* statename, unsigned short startFrame, unsigned short endFrame); void SetAnimationLoop(unsigned short startFrame, unsigned short endframe); void SetAnimationLoop(char* stateName); void SetFrame(unsigned short); unsigned short GetFrame(); int posX; int posY; int velX; int velY; private: Sprite sprite; int currentFrame; int totalFrames; int indexOffset; }; #endif |
Sprite Cpp...
Code: |
#include "gbaSprite.h" gbaSprite::gbaSprite(const unsigned short spriteTiles[], int width, int height, int Frames) { posX = 200; posY = 126; velX = 0; velY = 0; currentFrame = 0; totalFrames = Frames; indexOffset = height; sprite.attribute2 = 0*32; //tileIndex sprite.attribute0 = COLOR_256 | posY; //color mode, y pos //if( width == 8 && height == 8) // sprite.attribute1 = SIZE_8 | posX; //spriteSize, x pos //if( width == 16 && height == 16) // sprite.attribute1 = SIZE_16 | posX; //spriteSize, x pos //if( width == 32 && height == 32) sprite.attribute1 = SIZE_32 | posX; //spriteSize, x pos DMAFastCopy((void*)spriteTiles, (void*)SpriteData, sizeof(spriteTiles), DMA_32NOW); DMAFastCopy((void*)&sprite, (void*)SpriteMem, sizeof(sprite), DMA_32NOW); } void gbaSprite::UpdateOAM() { //Updates the OAM data from our private sprite memory DMAFastCopy((void*)&sprite, (void*)SpriteMem, sizeof(sprite), DMA_32NOW); } |
Guess:
It appears of if it is copying data over, but for some reason it seams to copy in data missing a chunk of the sprite... Just guessing... The first method displays the airplane fine, colorkeyed and all. The class, displays the arplane with the bottom half f the tale on the top half of the sprite rect, and the top half of the plane on the bottom half of the sprite rect. However it is colorkeyed properly.