Homebrew ds sprite coding help

keven3477

Fresh Prince of Lemonade
OP
Member
Joined
Jul 12, 2012
Messages
953
Trophies
0
Location
Somewhere i can never find.
XP
1,212
Country
United States
hi im new at making hombrew and I read some manuals on how to make homebrew.
however I tried to make a hombrew display a sprite but it didn't come out good.
I tried using the manual in patater to display the ship but the pixels were all fizzy and separated didn't even look like a ship at all.
Ive already spent 3 months searching how to succesfuly display sprites on google but no luck.
what im asking is can anyone give me a good tutorial on displaying 2d sprites

code I used to display sprite

Code:
void initSprites(OAMTable * 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;
    static const int BOUNDARY_VALUE = 32; /* This is the default boundary value
                                          * (can be set in REG_DISPCNT) */
    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 * shuttleInfo = &spriteInfo[SHUTTLE_OAM_ID];
    SpriteEntry * shuttle = &oam->oamBuffer[SHUTTLE_OAM_ID];
 
    /* Initialize shuttleInfo */
    shuttleInfo->oamId = SHUTTLE_OAM_ID;
    shuttleInfo->width = 64;
    shuttleInfo->height = 64;
    shuttleInfo->angle = 462;
    shuttleInfo->entry = shuttle;
 
    /*
    *  Configure attribute 0.
    *
    *  OBJCOLOR_16 will make a 16-color sprite. We specify that we want an
    *  affine sprite (via isRotateScale) here because we would like to rotate
    *  the ship.
    */
    shuttle->y = SCREEN_HEIGHT / 2 - shuttleInfo->height;
    shuttle->isRotateScale = 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(!shuttle->isRotateScale || (shuttleInfo->oamId < MATRIX_COUNT));
    shuttle->isSizeDouble = false;
    shuttle->blendMode = OBJMODE_NORMAL;
    shuttle->isMosaic = false;
    shuttle->colorMode = OBJCOLOR_16;
    shuttle->shape = OBJSHAPE_SQUARE;
 
    /*
    *  Configure attribute 1.
    *
    *  rotationIndex 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.
    */
    shuttle->x = SCREEN_WIDTH / 2 - shuttleInfo->width * 2 +
                    shuttleInfo->width / 2;
    shuttle->rotationIndex = shuttleInfo->oamId;
    shuttle->size = OBJSIZE_64;
 
    /*
    *  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.
    */
    shuttle->gfxIndex = nextAvailableTileIdx;
    nextAvailableTileIdx += orangeShuttleTilesLen / BYTES_PER_16_COLOR_TILE;
    shuttle->priority = OBJPRIORITY_0;
    shuttle->palette = shuttleInfo->oamId;
 
    /* Rotate the sprite */
    rotateSprite(&oam->matrixBuffer[shuttleInfo->oamId],
                shuttleInfo->angle);
 
 
 
    /* Copy over the sprite palettes */
    dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
                    orangeShuttlePal,
                    &SPRITE_PALETTE[shuttleInfo->oamId *
                                    COLORS_PER_PALETTE],
                    orangeShuttlePalLen);
 
 
    /* Copy the sprite graphics to sprite graphics memory */
    dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
                    orangeShuttleTiles,
                    &SPRITE_GFX[shuttle->gfxIndex * OFFSET_MULTIPLIER],
                    orangeShuttleTilesLen);
 
}

the red square in the file attached is the patater ship
 

Attachments

  • dsbrew.BMP
    288.1 KB · Views: 330

PypeBros

Well-Known Member
Newcomer
Joined
Oct 29, 2007
Messages
88
Trophies
0
Location
Belgium
Website
sylvainhb.blogspot.com
XP
453
Country
Belgium
It sounds like you're experiencing something like "yellow clouds" on this image:
test.png

That could be due to a mis-configuration of tiled vs. bitmap mode.
 

Wolfgange

Well-Known Member
Member
Joined
Feb 9, 2012
Messages
231
Trophies
1
XP
248
Country
United States
hi im new at making hombrew and I read some manuals on how to make homebrew.
however I tried to make a hombrew display a sprite but it didn't come out good.
I tried using the manual in patater to display the ship but the pixels were all fizzy and separated didn't even look like a ship at all.
Ive already spent 3 months searching how to succesfuly display sprites on google but no luck.
what im asking is can anyone give me a good tutorial on displaying 2d sprites

code I used to display sprite


the red square in the file attached is the patater ship

Liek mentioned above, I 100% recommend nightfox lib. With any questions you can ask foxi4. There's a nice full-length tutorial he made here:
https://gbatemp.net/threads/ds-programming-for-newbies.322106/


If you wanted to get better at c++ before hand, or take a look at some DS Graphics code in context, I recommend looking at an open source DS homebrew game (Such as MineDS).
 

Wolfgange

Well-Known Member
Member
Joined
Feb 9, 2012
Messages
231
Trophies
1
XP
248
Country
United States
i decide to use nightfox recently but I couldn't figure out how to convert into an .img file using the tools however I managed to fix the sprite so it finaly works as a header file
Nice. I know when I used NFLib, you have to manually open wingrit.exe and load your image and process it into a .img. So mess around with wingrit and you will figure out how.
 

keven3477

Fresh Prince of Lemonade
OP
Member
Joined
Jul 12, 2012
Messages
953
Trophies
0
Location
Somewhere i can never find.
XP
1,212
Country
United States
i managed to convert 1 sprite into .img and .pal but im having trouble displaying the sprite. i could manage to only display a small gray square whith 4 lines instead of the full sprite which is supposed to be a yu-gi-oh spell card template
 

keven3477

Fresh Prince of Lemonade
OP
Member
Joined
Jul 12, 2012
Messages
953
Trophies
0
Location
Somewhere i can never find.
XP
1,212
Country
United States
yes but I found out (after trial and error) sprites have to be in a size of 32 or 64 of width or length so it could show properly and I finaly managed to display a sprite. I just wish I knew what sizes are allowed because I want to display a sprite higher than 100, I have checked and 128 or 256 don't work
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • BakerMan @ BakerMan:
    fuck ubisoft, and fuck activision
    +1
  • realtimesave @ realtimesave:
    Nintendo needs to release a new console, switch is getting such shitty little games lately lol it's pathetic
  • Purple_Heart @ Purple_Heart:
    Lmao a new flashcart... The Unlock Switch... I knew it's not fake xD
    +1
  • NinStar @ NinStar:
    A new consoles won't solve that problem
  • NinStar @ NinStar:
    It will actually make it worse
  • The Real Jdbye @ The Real Jdbye:
    well actually
    a new console won't do anything right now, because the games are still in development, that's why there are few games being released
  • The Real Jdbye @ The Real Jdbye:
    it won't make the games finish any faster
  • Veho @ Veho:
    2/3rds of launch titles for the Switch 2 will just be lazy ports of Switch games anyway.
  • The Real Jdbye @ The Real Jdbye:
    probably
  • The Real Jdbye @ The Real Jdbye:
    maybe mario kart 9 will be a launch title
  • The Real Jdbye @ The Real Jdbye:
    i really want a new mario kart
  • Veho @ Veho:
    What, you mean the endless stream of DLCs doesn't count?
  • Veho @ Veho:
    Why develop a new game when you can just sell season passes forever?
  • Veho @ Veho:
    I'm still on MKDS so I'm not bothered :tpi:
  • The Real Jdbye @ The Real Jdbye:
    i like the dlc tbh, i'd like a new game more
  • ZeroT21 @ ZeroT21:
    but the current version is still selling fine at full price
  • SylverReZ @ SylverReZ:
    Hello
  • ZeroT21 @ ZeroT21:
    sup
    +1
  • SylverReZ @ SylverReZ:
    @realtimesave, You seen the Unlock Switch flashcart yet?
  • K3Nv2 @ K3Nv2:
    I'll see the 19.0 update that blocks use ability to it
    +1
  • K3Nv2 @ K3Nv2:
    Lol newegg+
    Screenshot-20240423-053504-Gmail.jpg
  • S @ salazarcosplay:
    does update 19 really block it
  • SylverReZ @ SylverReZ:
    Update 19 never came out yet. Just the 18.1.
    SylverReZ @ SylverReZ: Update 19 never came out yet. Just the 18.1.