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 > Problems with text...

#67184 - Linkiboy - Mon Jan 16, 2006 3:07 am

Well, I finally got sprites moving, and they detect their collison (yay!), and I got text to show up, but in seperate .nds files. When I try to combine The two scrips, It compiles with no errors, but The text doesn't show up...

Text script:

Code:

#include "..\nds.h"
#include "..\memory.h"
#include "..\screen.h"
#include "..\system.h"
#include "..\sprtext.h"

int main()
{
int i;
powerON(POWER_ALL);
videoSetMode(MODE_0_2D | SPR_1D_LAYOUT | SPR_ACTIVE);
VRAM_BANK_A(VRAM_SPRITE);
SetupText();
Print(0,0,0x01,0);
PrintString(8,0,"Hello",1);
PrintNum(16,0,0xff,6);
}


Here is the combined script:
Code:

#include "..\nds.h"
#include "..\memory.h"
#include "..\screen.h"
#include "..\system.h"
#include "..\keys.h"
#include "..\ipc.h"
#include "..\sprtext.h"
#include "spr.h"

int x,y,spritex,spritey,tempx,tempy,wait,i;

void removesprites() //function, outside main, must be called from within main
{
for(i = 0; i < 128; i++)
OAM[i * 4] = ATTR0_DISABLED;
}

int main()
{
powerON(POWER_ALL);
videoSetMode(MODE_0_2D | SPR_1D_LAYOUT | SPR_ACTIVE); //activates 2d and turns on sprites in 1d mode
VRAM_BANK_A(VRAM_SPRITE); //sprite vram
SetupText();
Print(0,0,0x01,0);
PrintString(8,0,"Hello",1);
PrintNum(16,0,0xff,6);
SPRITE_PALETTE[1] = RGB(31,0,0); //sprites pallet
for(i = 0; i < 256; i++)
SPRITE_PALETTE[i] = ((u16*)testPalette)[i];
for(i = 0; i < 32*16; i++)
SPRITE_GFX[i] = ((u16*)testData)[i];
for(i = 0; i < 128; i++)
removesprites(); //uses function to remove sprites from the screen
spritey = 50;
spritex = 100;
y = 100;
x = 200;
while(1)
{
IPC[0] = spritex;
IPC[2] = spritey;
if(READ_KEYS & KEY_UP)
{
tempy = y;
tempy--;
if(tempy>0 & (x<spritex-32 | x>spritex+32 | tempy<spritey-32 | tempy>spritey+32)){y = tempy;}
}
if(READ_KEYS & KEY_DOWN)
{
tempy = y;
tempy++;
if(tempy<184 & (x<spritex-32 | x>spritex+32 | tempy<spritey-32 | tempy>spritey+32)){y = tempy;}
}
if(READ_KEYS & KEY_LEFT)
{
tempx = x;
tempx--;
if(tempx>0 & (tempx<spritex-32 | tempx>spritex+32 | y<spritey-32 | y>spritey+32)){x = tempx;}
}
if(READ_KEYS & KEY_RIGHT)
{
tempx = x;
tempx++;
if(tempx<248 & (tempx<spritex-32 | tempx>spritex+32 | y<spritey-32 | y>spritey+32)){x = tempx;}
}
tempx = IPC[0];
tempy = IPC[2];
if(IPC[1]){
IPC[1] = 0;
if(tempx>0 & (tempx<x-32 | tempx>x+32 | spritey<y-32 | spritey>y+32)){spritex=tempx;}
}
if(IPC[3]){
IPC[3] = 0;
if(tempy>0 & (spritex<x-32 | spritex>x+32 | tempy<y-32 | tempy>y+32)){spritey=tempy;}
}
if(READ_KEYS & KEY_A)
{
tempx = spritex;
tempx++;
if(tempx<248 & (tempx<x-8 | tempx>x+8 | spritey<y-8 | spritey>y+8)){spritex = tempx;}
}
if(READ_KEYS & KEY_B)
{
tempy = spritey;
tempy++;
if(tempy<184 & (spritex<x-8 | spritex>x+8 | tempy<y-8 | tempy>y+8)){spritey = tempy;}
}
OAM[0] = ATTR0_COLOR_256 | ATTR0_SQUARE | spritey; //ATTR0, atribute which controls sprites colour, shape and x coord
OAM[1] = ATTR1_SIZE_32 | spritex; //ATTR1 is size and y coord
OAM[2] = 0; //ATTR2 is sprite img no.
OAM[4] = ATTR0_COLOR_256 | ATTR0_SQUARE | y; //ATTR0, atribute which controls sprites colour, shape and y coord
OAM[5] = ATTR1_SIZE_32 | x; //ATTR1 is size and x coord
OAM[6] = 0; //ATTR2 is sprite img no.
//oam3 rotates and zooms but is not needed
for(wait=0;wait<1000;wait++) wait = wait;
WaitForVBlank();
}
}


If you need any other pieces of code ask me.

So what am i doing wrong?

#67238 - Maverick - Mon Jan 16, 2006 12:10 pm

That is a strange piece of code

Youre using sprites 0 to 6 to display text, using the remove sprites function and then using 0 and 1 to display your sprites
_________________
http://downtou.ne1.net/

#67266 - Linkiboy - Mon Jan 16, 2006 4:54 pm

So how would I have it so that the sprites and text were both shown on the same time? I've been messing around with the code, Got the text to show up, but it turned my sprites into ABCDEFGHIJKLMNO packed together in a square...

#67298 - Maverick - Mon Jan 16, 2006 8:14 pm

Well, in sprtext, the letters are placed into the data area from 0 to 2687, so you could start from here adding your data if you wanted to, or you could use bgtext for your text and have none of the sprite area taken up by the letters. The letters data takes up the same space for the backgrounds, so if you were using backgrounds and bgtext together, you would have to do the same thing
_________________
http://downtou.ne1.net/

#67300 - Linkiboy - Mon Jan 16, 2006 9:28 pm

Maverick wrote:
Well, in sprtext, the letters are placed into the data area from 0 to 2687, so you could start from here adding your data if you wanted to, or you could use bgtext for your text and have none of the sprite area taken up by the letters. The letters data takes up the same space for the backgrounds, so if you were using backgrounds and bgtext together, you would have to do the same thing
Ok, thanks. BTW will you ever finish the rest of the tutorials on your site?

#67309 - Maverick - Mon Jan 16, 2006 10:24 pm

ATM, theyre not popular at all, and i havent been getting any feedback from the ones i have done, but i am currently in the process of porting my code to libnds and will be updating and continuing with my DS section once this is done

Thankyou for your interest
_________________
http://downtou.ne1.net/