观看视频:https://youtu.be/i2EXKY3EQPo 龙运动不流畅。就好像所有帧都在同一时间变化一样。我做错了什么?
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);
答案 0 :(得分:1)
尝试绘制各种值的结果:
| frameCount | curFrame |
| ---------- | -------- |
| 0 | 0 |
| 1 | 0 |
| 2 | 0 |
| ...... | ...... |
| 49 | 0 |
| 50 | 1 |
| 51 | 2 |
| 52 | 3 |
| 54 | 4 |
| 55 | 5 |
| 56 | 0 |
| 0 | 0 |
请注意,当frameCount
达到50时,它会按顺序突破所有帧,然后仅在动画完成后重置。您需要重置frameCount
每个时间范围frameDelay