精灵;在C ++ Allegro 5中,改变帧不流畅

时间:2018-01-20 12:34:25

标签: c++ allegro allegro5

观看视频: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);

这是精灵:enter image description here

1 个答案:

答案 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