#163045 - anomalous_underdog - Sat Sep 20, 2008 11:45 am
I'm making scrollbar GUI's and I decided to use HW sprites so they can be moved around easily.
This is how the sprite should look like:
[Images not permitted - Click here to view it]
This is how it looks like right now:
[Images not permitted - Click here to view it]
Its the one on the bottom screen, the one floating on the white area. (That's only one sprite) It certainly shouldn't look like that. Any help is appreciated.
I based my code off from the patatersoft manual:
Last edited by anomalous_underdog on Mon Sep 22, 2008 2:35 pm; edited 1 time in total
This is how the sprite should look like:
[Images not permitted - Click here to view it]
This is how it looks like right now:
[Images not permitted - Click here to view it]
Its the one on the bottom screen, the one floating on the white area. (That's only one sprite) It certainly shouldn't look like that. Any help is appreciated.
I based my code off from the patatersoft manual:
Code: |
typedef struct { int oamId; int width; int height; int angle; SpriteEntry * entry; } SpriteInfo; void initSprites(tOAM * oam, SpriteInfo *spriteInfo) { /* Define some sprite configuration specific constants. * * We will use these to compute the proper index into memory for certain * tiles or palettes. * * OFFSET_MULTIPLIER is calculated based on the following formula from * GBATEK (http://nocash.emubase.de/gbatek.htm#dsvideoobjs): * TileVramAddress = TileNumber * BoundaryValue * Since SPRITE_GFX is a uint16*, the compiler will increment the address * it points to by 2 for each change in 1 of the array index into * SPRITE_GFX. (The compiler does pointer arithmetic.) */ static const int BYTES_PER_16_COLOR_TILE = 32; static const int COLORS_PER_PALETTE = 16; // This is the default boundary value // (can be set in REG_DISPCNT) static const int BOUNDARY_VALUE = 32; static const int OFFSET_MULTIPLIER = BOUNDARY_VALUE / sizeof(SPRITE_GFX[0]); // Keep track of the available tiles int nextAvailableTileIdx = 0; /* Create the ship sprite. */ static const int SHUTTLE_OAM_ID = 0; assert(SHUTTLE_OAM_ID < SPRITE_COUNT); SpriteInfo * scrollbarInfo = &spriteInfo[SHUTTLE_OAM_ID]; SpriteEntry * scrollbarSprite = &oam->spriteBuffer[SHUTTLE_OAM_ID]; /* Initialize scrollbarInfo */ scrollbarInfo->oamId = SHUTTLE_OAM_ID; scrollbarInfo->entry = scrollbarSprite; scrollbarInfo->width = 7; scrollbarInfo->height = 23; scrollbarInfo->angle = 0; scrollbarSprite->posX = 70; scrollbarSprite->posY = 50; /* * Configure attribute 0. * * OBJCOLOR_16 will make a 16-color sprite. We specify that we want an * affine sprite (via isRotoscale) here because we would like to rotate * the ship. */ //scrollbarSprite->isRotoscale = true; /* This assert is a check to see a matrix is available to store the affine * transformation matrix for this sprite. Of course, you don't have to have * the matrix id match the affine id, but if you do make them match, this * assert can be helpful. */ assert(!scrollbarSprite->isRotoscale || (scrollbarInfo->oamId < MATRIX_COUNT)); scrollbarSprite->rsDouble = false; scrollbarSprite->isMosaic = false; scrollbarSprite->objMode = OBJMODE_NORMAL; scrollbarSprite->colMode = OBJCOLOR_16; scrollbarSprite->objShape = OBJSHAPE_TALL; /* * Configure attribute 1. * * rsMatrixId refers to the loation of affine transformation matrix. We * set it to a location computed with a macro. OBJSIZE_64, in our case * since we are making a square sprite, creates a 64x64 sprite. */ scrollbarSprite->rsMatrixIdx = ATTR1_ROTDATA(scrollbarInfo->oamId); scrollbarSprite->objSize = OBJSIZE_32; /* * Configure attribute 2. * * Configure which tiles the sprite will use, which priority layer it will * be placed onto, which palette the sprite should use, and whether or not * to show the sprite. */ scrollbarSprite->tileIdx = nextAvailableTileIdx; nextAvailableTileIdx += scrollbarHandle_selectedTilesLen / BYTES_PER_16_COLOR_TILE; scrollbarSprite->objPriority = OBJPRIORITY_2; scrollbarSprite->objPal = scrollbarInfo->oamId; /* Rotate the sprite */ //rotateSprite(&oam->matrixBuffer[scrollbarInfo->oamId], // scrollbarInfo->angle); /*************************************************************************/ /* Copy over the sprite palettes */ dmaCopyHalfWords(SPRITE_DMA_CHANNEL, scrollbarHandle_selectedPal, &SPRITE_PALETTE[scrollbarInfo->oamId * COLORS_PER_PALETTE], scrollbarHandle_selectedPalLen); /* Copy the sprite graphics to sprite graphics memory */ dmaCopyHalfWords(SPRITE_DMA_CHANNEL, scrollbarHandle_selectedTiles, &SPRITE_GFX[scrollbarSprite->tileIdx * OFFSET_MULTIPLIER], scrollbarHandle_selectedTilesLen); } |
Last edited by anomalous_underdog on Mon Sep 22, 2008 2:35 pm; edited 1 time in total