libnds noob question, loading sprites

Discussion in 'NDS - Emulation and Homebrew' started by _V1qY, Apr 21, 2014.

  1. _V1qY
    OP

    _V1qY GBAtemp Regular

    Member
    138
    36
    May 31, 2012
    I am trying to load a sprite, but just I can't get it to work.

    My code is based on http://www.dev-scene.com/NDS/Tutorials_Day_5 .

    Here is the simplified version, nothing shows up.

    Code:
      consoleDemoInit();
     
      videoSetMode(MODE_0_2D);
      vramSetPrimaryBanks(VRAM_A_MAIN_SPRITE, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
         
      oamInit(&oamMain, SpriteMapping_Bmp_1D_128, false);
      u16 *gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
     
      dmaCopy(tile_data, gfx, sizeof(tile_data));
      dmaCopy(palette, SPRITE_PALETTE, sizeof(palette));
     
      while(1) {
          scanKeys();
         
          oamSet(&oamMain, 0, 64, 32, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, gfx, 0, false, false, false, false, false);
          oamUpdate(&oamMain);
         
          swiWaitForVBlank();
      }
     
  2. Plainscript

    Plainscript GBAtemp Regular

    Member
    110
    13
    Nov 18, 2012
    Netherlands
    Just tested it:

    It's not you - I get the same results.. That is, on the referenced page.

    In your code, I don't think the
    Code:
    consoleDemoInit();
    ..gonna work, because you want to display sprites. Not a text-based console. But I could be missing something. :)

    EDIT: Try the examples\nds\Graphics\Sprites\animate_simple\source route from your Devkitpro folder to see something like this, but working. ;)
     
  3. _V1qY
    OP

    _V1qY GBAtemp Regular

    Member
    138
    36
    May 31, 2012
    I used the consoleDemoInit so that I could print some debug text before I tried to display the sprite. This was just a simplified version of my code.

    I've removed the consoleDemoInit and all printf calls but I still can't get it to display.

    I've had a look at the few examples which come with devkitPro, but I can't tell the difference between mine and theirs.

    This is such simple code, are you sure that there's nothing obvious that you can see which is wrong? Plainscript
     
  4. Plainscript

    Plainscript GBAtemp Regular

    Member
    110
    13
    Nov 18, 2012
    Netherlands
    Just took a second look at it.

    Try this:

    At the last lines, during the while loop:

    Code:
    while (1) //infinite loop
    {
    oamSet(&oamMain,0,64,32,0,0,SpriteSize_64x64,SpriteColorFormat_256Color,gfx,0,false,false,false,false,false);
    swiWaitForVBlank();
    oamUpdate(&oamMain);
    }
    It's still based on the link in the first post.

    Notice how it is placed:

    oamSet
    swiWaitForVBlank
    oamUpdate

    It works now. :)
     
  5. _V1qY
    OP

    _V1qY GBAtemp Regular

    Member
    138
    36
    May 31, 2012
    Thanks very much for your help, unfortunately I still can not get this to work. I've sent you some complete code to check, hopefully there is just something simple wrong with my code.
     
  6. Plainscript

    Plainscript GBAtemp Regular

    Member
    110
    13
    Nov 18, 2012
    Netherlands
    Just got the PM. Bout to look into it. :)
     
  7. _V1qY
    OP

    _V1qY GBAtemp Regular

    Member
    138
    36
    May 31, 2012
    Whoops, remember to uncomment this part so it looks like this:

    I accidentally removed that bit when removing printf calls.

    The result is slightly better now, something appears on the top screen, and I think the palette is right! The tiles seem wrong though.
     
  8. _V1qY
    OP

    _V1qY GBAtemp Regular

    Member
    138
    36
    May 31, 2012
    I have read that NDS icons are just standard tiles and palettes, so that shouldn't be the issue.
     
  9. _V1qY
    OP

    _V1qY GBAtemp Regular

    Member
    138
    36
    May 31, 2012
    Nevermind, I got it to work!
     
  10. Plainscript

    Plainscript GBAtemp Regular

    Member
    110
    13
    Nov 18, 2012
    Netherlands
    Share, share!

    The solution, that is.
     
  11. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,670
    21,708
    Sep 13, 2009
    Poland
    Gaming Grotto
    There's a sprite example that comes with libnds, y'know. Don't rely on online resources that may or may not be up-to-date, always consult the included documentation.