gfx pointer arrays-- please help me!

Post Reply
DayTripperID
Posts: 22
Joined: Tue Aug 07, 2012 8:57 pm

gfx pointer arrays-- please help me!

Post by DayTripperID » Thu Aug 30, 2012 3:52 pm

I have a png file that is 16*480 pixels, enough for thirty 16x16 gfx frames. Each frame is a letter of the alphabet, plus 4 more for some punctuation characters. I'm trying to allocate memory for an array of 30 pointers and then copy each frame into one of the pointers. Then I want to read characters from a string and set the corresponding sprite frames into oam. Here is my code for this right now:

Code: Select all

#include "alpha_gfx.h"
#include <string>
#include<nds.h>

using namespace std;

void main(){
	
	/* General counting variable. */
	unsigned int i;
	
        /* Variable to index pointer array */	
	int pIndex = 0;
	
        /* Pointer array to reference frames in oam */
	u16 * alphaTilesPtr[30];
	
	for( i=0; i<30; i++){
	/* Allocate memory for alpha_gfxTiles. */
	alphaTilesPtr[i] = oamAllocateGfx(oam_sub, SpriteSize_16x16, SpriteColorFormat_16Color);
	
	/* Copy tiles into memory. */
	swiCopy((void*)alpha_gfxTiles[32*i], (void*)alphaTilesPtr[i], alpha_gfxTilesLen/30);
	}
	
	/* Copy alpha_gfx palette into allocated memory */
	swiCopy(alpha_gfxPal, SPRITE_PALETTE_SUB, alpha_gfxPalLen);
	
	/* String with characters. */
	string hudStr = "SHIELD";
	
	/* Read character strings and convert into alpha sprites. */
	for (i = 0; i < hudStr.size(); i++) {
		     
			 if(hudStr[i] == 'A') pIndex= 0;
		else if(hudStr[i] == 'B') pIndex= 1;
		else if(hudStr[i] == 'C') pIndex= 2;
		else if(hudStr[i] == 'D') pIndex= 3;
		else if(hudStr[i] == 'E') pIndex= 4;
		else if(hudStr[i] == 'F') pIndex= 5;
		else if(hudStr[i] == 'G') pIndex= 6;
		else if(hudStr[i] == 'H') pIndex= 7;
		else if(hudStr[i] == 'I') pIndex= 8;
		else if(hudStr[i] == 'J') pIndex= 9;
		else if(hudStr[i] == 'K') pIndex=10;
		else if(hudStr[i] == 'L') pIndex=11;
		else if(hudStr[i] == 'M') pIndex=12;
		else if(hudStr[i] == 'N') pIndex=13;
		else if(hudStr[i] == 'P') pIndex=14;
		else if(hudStr[i] == 'P') pIndex=15;
		else if(hudStr[i] == 'Q') pIndex=16;
		else if(hudStr[i] == 'R') pIndex=17;
		else if(hudStr[i] == 'S') pIndex=18;
		else if(hudStr[i] == 'T') pIndex=19;
		else if(hudStr[i] == 'U') pIndex=20;
		else if(hudStr[i] == 'V') pIndex=21;
		else if(hudStr[i] == 'W') pIndex=22;
		else if(hudStr[i] == 'X') pIndex=23;
		else if(hudStr[i] == 'Y') pIndex=24;
		else if(hudStr[i] == 'Z') pIndex=25;
	        //last 4 frames not implemented yet. =)

           oamSet (&OamSub, i, (34+(i*16)), 34, 0, 0, SpriteSize_16x16, SpriteColorFormat_16Color, alphaTilesPtr[pIndex],
                             -1, false, false, false, false, false);
	}

       while(TRUE){
          swiWaitForVblank();
          oamUpdate(&OamSub);
       }

}
But the sprites don't show up on the sub screen. I tested it out using a single pointer, i.e. one that is NOT a member of an array, and I could get whichever frame I wanted on the screen, so I know that finding the offset into the gfx data is working correctly. But whenever I try to put one frame each into a member of an array, they never show up on screen.

Here is the image I'm working with: http://postimage.org/image/7zbntsw2j/

Can someone please help me with this problem? Thanks :!:

DayTripperID
Posts: 22
Joined: Tue Aug 07, 2012 8:57 pm

Re: gfx pointer arrays-- please help me!

Post by DayTripperID » Thu Aug 30, 2012 7:31 pm

OK I solved it. alpha_gfxTiles[i*32] needed to be &alpha_gfxTiles[i*32] in the swiCopy line. Arrays and their shenanigans. :lol:

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests