0

Watch the video: https://youtu.be/i2EXKY3EQPo The dragon movement is not fluid. It's like if all the frames were changing at the same time. What am I doing wrong?

shipImage = al_load_bitmap("dragon_stationary.png");
ship.maxFrame = 5;
ship.curFrame = 0;
ship.frameCount = 0;
ship.frameDelay = 50;
ship.frameWidth = 180;
ship.frameHeight = 126;
ship.animationColumns = 5;
ship.animationDirection = 1;
//this occurs every 1/60 of a second
void drawShip(SpaceShip &ship, ALLEGRO_BITMAP *flyingShip) {
    if (++ship.frameCount >= ship.frameDelay) {
        if (++ship.curFrame >= ship.maxFrame) {
            ship.curFrame = 0;
            ship.frameCount = 0;
        }
    }

    al_draw_bitmap_region(ship.image, ship.curFrame * ship.frameWidth, 0, ship.frameWidth, ship.frameHeight, ship.x, ship.y, 0);

This is the sprite:enter image description here

John
  • 105
  • 10

1 Answers1

1

Try plotting out what happens for various values:

| frameCount | curFrame |

| ---------- | -------- |

| 0 | 0 |

| 1 | 0 |

| 2 | 0 |

| ... | ... |

| 49 | 0 |

| 50 | 1 |

| 51 | 2 |

| 52 | 3 |

| 54 | 4 |

| 55 | 5 |

| 56 | 0 |

| 0 | 0 |

Note that when frameCount hits 50, it blasts through all your frames in sequence, then only resets once the animation is complete. You need to reset frameCount every timme it reaches frameDelay

rcorre
  • 6,477
  • 3
  • 28
  • 33
  • Sorry about the format, apparently stackoverflow [doesn't support tables](https://meta.stackexchange.com/questions/73566/is-there-markdown-to-create-tables) – rcorre Jan 20 '18 at 21:07
  • Thanks! Another thing, can you please tell me how to pass an array of bitmaps to a function? ALLEGRO_BITMAP * shipImage[maxFrameShip]; initShip(ship, shipImage[maxFrameShip]); void initShip(SpaceShip &ship, ALLEGRO_BITMAP *image) { ship.image[0] = image[0]; } this is the way I have it now and it does not work "expression must be a pointer to a complete object type" What's the correct way? – John Jan 20 '18 at 21:19
  • Search for that error, then open a new question if you can't find an answer – rcorre Jan 22 '18 at 19:21