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.

Beginners > A NDS newbie programmer needs help[solved]

#175477 - NaclChan - Tue Nov 30, 2010 5:55 pm

Hello everyone:
I am a newbie NDS programmer from China,recently I am working hard on how to display my animate sprites correctly,but I always get a wrong one.When I want to display my sprite at the left-top(0,0), the sprite shows up near (30,30). The picture below shows what happened.

[img]
http://photo.renren.com/photo/36105/photo-3742550579?curpage=0&t=
[/img]

I checked my code,but I found nothing strange.So I come here to see if I can get some help from you. Sorry to bother you guys.

The code below is how I set the display mode and things like that
Code:

   //设置图像引擎的工作模式
   videoSetMode(MODE_5_2D);
   //把精灵的存储空间映射到BankA,根据libnds的说明,只有特定的bank才能映射
   vramSetBankA(VRAM_A_MAIN_SPRITE);
   
   irqInit();
   irqEnable(IRQ_VBLANK);
   irqSet(IRQ_VBLANK,vBlank);


Here are the code I used to set my sprite
Code:

   //设置精灵的映射方式为1D映射,现在对这个还不是相当的了解
   oamInit(&oamMain, SpriteMapping_1D_128, false);

   //为精灵的Tile数据申请一个存储的空间,mainSprite.gfx指向新申请的空间的基址
   //并设置精灵的显示为256色的tile方式,不是bmp方式
   mainSprite.gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
   //在控制精灵动作的时候有一个指向实际要显示tile的基址,初始时为整个tile数据的基址
   baseGfx = mainSprite.gfx;
   
   //将tile数据,调色盘数据载入相应的空间之中
   dmaCopyHalfWords(3,test_Char,mainSprite.gfx,sizeof(test_Char));
   dmaCopyHalfWords(3,test_Palette,SPRITE_PALETTE,sizeof(test_Palette));


Now I will show the strcture of my sprite
Code:

typedef struct 
{
    signed int x;
    signed int y;
    int speed;
    SpriteSize size;
    SpriteColorFormat format;
    u16* gfx;
}MySprite;

//定义一个精灵的结构体,存放精灵的初始信息
MySprite mainSprite = {0,0,10,SpriteSize_32x32,SpriteColorFormat_256Color,0};


BTW:I am glad to say hello to everyone,thank you


Last edited by NaclChan on Wed Dec 01, 2010 11:36 am; edited 1 time in total

#175478 - elhobbs - Tue Nov 30, 2010 6:06 pm

hello NaclChan - after a brief look at your code I can tell you that "irqInit();" should not be called with current versions of libnds. this call has been moved into the asm startup code and does not need to used in your code. Calling it in your code will cause problems.

there may be other problems though... good luck!

#175483 - NaclChan - Wed Dec 01, 2010 11:35 am

Hello elhobbs:
Thank u 4 your reply,and I have taken your advice.
I have known the reason why my sprite doesn't display at the correct pixel. I found that I had turned on the rotation and the sizeDouble function of the sprite.
Here is the code before modification. The 10th parameter and the 11th parameter didn't set correctly.The sprite size shows on the screen is twice than I wantted,so the position of the sprite also shifted.
Code:

   //设定精灵的各种属性
   oamSet
   (
      &oamMain,
      0,
      mainSprite.x,
      mainSprite.y,
      0,
      0,
      SpriteSize_32x32,
      SpriteColorFormat_256Color,
      baseGfx + offSet,
      0,
      true,
      false,
      false,
      false,
      false
   );


Here is the code after modification.I have tested them, they can work as I wantted.
Code:

   //设定精灵的各种属性
   oamSet
   (
      &oamMain,
      0,                                 //id
      mainSprite.x,
      mainSprite.y,
      0,
      0,
      SpriteSize_32x32,
      SpriteColorFormat_256Color,
      baseGfx + offSet,
      -1,                               //turn off rotation
      false,                           //sizeDouble off
      false,
      false,
      false,
      false
   );



Anyway,I want to say thank u,for your reply.