-
Notifications
You must be signed in to change notification settings - Fork 51
Animations
Zal0 edited this page Sep 13, 2021
·
5 revisions
Let's make our Sprite animate when walking
- Open the file player.gbr with Game Boy Tile Designer (you should associate the extension *.gbr to be always opened whit this program if you haven't done it yet)
- Change the aspect of the Sprite by a boy and add a couple of frames for the walking animation. Something like this
- Save your file (do not export! ZGB will take care of this stuff now)
- If you Build the project now you should see the new Sprite instead of the Game Boy
- Animations are declared as arrays of UINT8, the first value is the number of frames. Declare the next arrays on SpritePlayer.c
const UINT8 anim_idle[] = {1, 0}; //The first number indicates the number of frames
const UINT8 anim_walk[] = {2, 1, 2};
- And now you can animate your character like this:
void UPDATE() {
if(KEY_PRESSED(J_UP)) {
THIS->y --;
SetSpriteAnim(THIS, anim_walk, 15);
}
if(KEY_PRESSED(J_DOWN)) {
THIS->y ++;
SetSpriteAnim(THIS, anim_walk, 15);
}
if(KEY_PRESSED(J_LEFT)) {
THIS->x --;
SetSpriteAnim(THIS, anim_walk, 15);
}
if(KEY_PRESSED(J_RIGHT)) {
THIS->x ++;
SetSpriteAnim(THIS, anim_walk, 15);
}
if(keys == 0) {
SetSpriteAnim(THIS, anim_idle, 15);
}
}