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.

Graphics > Anamation?

#68475 - Fenderocker - Tue Jan 24, 2006 10:27 pm

I need to make animated sprites for my RPG game that I am making. I also need to make a short intro anamation. how would I go about doing this and also If I made it do something like this:
Code:
draw frame
draw next frame
ect...


I'm afraid that it might take up too much memory.......
any help would be greatly appreciated!!!!

#68501 - gs2phateon - Wed Jan 25, 2006 3:06 am

I'm no expert on this, but I've heard that you could draw all of the frames of the animation with the original sprite, all stacked in the same bitmap array.

Then you would draw the sprite based on the frame number you want times the total number of tiles or pixels in the sprite.

So if you were making a 32x32 sprite in a bitmap mode and you drew frame number 6 it would start at something like:

sprite[frame * (32x32)]

And frame would increase every time to go to the next frame of animation.

I hope this kinda helps, but like I said I'm no expert. I'm working on something that will require animation, and this is the way I plan on doing it.

#68502 - Fenderocker - Wed Jan 25, 2006 4:03 am

thanks that helped a little bit........but I still need some information on how to code it....

#68547 - nmain - Wed Jan 25, 2006 4:57 pm

Fenderocker wrote:
thanks that helped a little bit........but I still need some information on how to code it....


Animated sprites: if you're short on vram, dma in the replacement sprite tiles in the animation on vblank. http://www.gbadev.org/files/managing-sprite-vram.txt

Otherwise, change the OAM entry to point to the other tiles (which are already in vram) for the next frame of the animation.

#68802 - Fenderocker - Thu Jan 26, 2006 9:14 pm

is there an easier way to make animated sprites than to make to draw frame one then draw frame two ect.... I think that that could take a whole lot of code.....

#68804 - Codax - Thu Jan 26, 2006 9:52 pm

If you place your sprite's frames of animations sequentially in VRAM it's actually very easy to do animating. Here's what you'll need assuming the sprite you wish to animate is 8x8 and has 30 frames of animation


Code:


//Location of the first frame of the animation in the SPRITE_GFX
const int initialGFXID =  1; 

 //Location of the last frame of the animation in the SPRITE_GFX
const int lastGFXID = 30;

 //How many 8x8 tiles make up this sprite
const int sizeofsprite = 1;


while(1)
{
  //sprite datastructure contains a gfxID and the copy of the OAM Attributes

  sprite.gfxID += sizeofsprite; //Here we set up the next frame

  //Now we double check to make sure it's valid
  if (sprite.gfxID > lastGFXID)
       sprite.gfxID = initialGFXID; //This will loop it back to the first frame

  //Now update the OAM attribute
  sprite.oam->attribute[2] = ATTR2_PALETTE(0) |  sprite.gfxID;

  //Finaly we do the true OAMUpdate
  swiWaitForVBlank();
  updateOAM();
}



And now you have a looping animation. YAY! It'll be going pretty fast so if you want to slow it down, just count the Vblanks and instead of incrementing it every Vblank, do it every other. Enjoy!
_________________
Codax
Dragon's Den Unlimited
http://www.DrgnDen.com

#68862 - Fenderocker - Fri Jan 27, 2006 3:08 am

I'll have to try that....