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
  • AncientBoi @ AncientBoi:
    :rofl2::tpi::rofl2: I meant his eyes :tpi::rofl2::tpi:
  • ZeroT21 @ ZeroT21:
    :toot:blow me then @K3Nv2
  • K3Nv2 @ K3Nv2:
    Nah I'm straight but you're more than welcome to blow ancientboi
  • ZeroT21 @ ZeroT21:
    LOL, which straight person does not make gay jokes?
    +1
  • K3Nv2 @ K3Nv2:
    I'm straight but we can whack dicks together
  • ZeroT21 @ ZeroT21:
    nah, I'm gud over here, no need for sword fights

    :glare:
    +1
  • K3Nv2 @ K3Nv2:
    Dick slang
  • K3Nv2 @ K3Nv2:
    See ancientboi already has a crush on you
  • AncientBoi @ AncientBoi:
    [brings my ⚔️ ] On Guard :D:evil::wub:
  • K3Nv2 @ K3Nv2:
    Looks more like a dagger to me
  • AncientBoi @ AncientBoi:
    Pffffft I have a crush on everybody
  • ZeroT21 @ ZeroT21:
    I see no problem, unless i happen to grow another gender one day. Too bad it ain't now
  • K3Nv2 @ K3Nv2:
    Thought you already had both hotswappable gender fluid
  • ZeroT21 @ ZeroT21:
    Enjoy whatever life chucks your way

    :teach:
    +1
  • K3Nv2 @ K3Nv2:
    Deeze nuts
  • AncientBoi @ AncientBoi:
    Dem Nutz
  • ZeroT21 @ ZeroT21:
    'Em nutters
  • AncientBoi @ AncientBoi:
    M&M nutz
    +1
  • K3Nv2 @ K3Nv2:
    Slim anus nutter
  • AncientBoi @ AncientBoi:
    :unsure::unsure::unsure: I might go buy them M&M w/nuts. I gotta go out to pay the rent anyway
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    Eat a Snickers!
  • Psionic Roshambo @ Psionic Roshambo:
    Almond Joys got nuts!
    Psionic Roshambo @ Psionic Roshambo: Almond Joys got nuts!