【问题标题】:Sprites; changing frames is not fluid in C++ Allegro 5精灵;在 C++ Allegro 5 中改变帧并不流畅
【发布时间】:2018-06-29 14:02:42
【问题描述】:

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

这是精灵:

【问题讨论】:

    标签: c++ allegro allegro5


    【解决方案1】:

    尝试绘制各种值会发生什么:

    |帧数 | 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 时,它会依次遍历所有帧,然后仅在动画完成后重置。每次到达frameDelay时,您都需要重置frameCount

    【讨论】:

    • 对不起格式,显然是stackoverflow doesn't support tables
    • 谢谢!另一件事,你能告诉我如何将位图数组传递给函数吗? ALLEGRO_BITMAP * shipImage[maxFrameShip]; initShip(船,shipImage[maxFrameShip]); void initShip(SpaceShip &ship, ALLEGRO_BITMAP *image) { ship.image[0] = image[0];这就是我现在的方式,它不起作用“表达式必须是指向完整对象类型的指针”正确的方式是什么?
    • 搜索该错误,如果找不到答案,请打开一个新问题
    猜你喜欢
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多