欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Qt平移动画

程序员文章站 2022-06-15 14:49:19
...
void Pokemon::moveTo(int x, int y)
{
    /*
    stop();
    state = MOVE;
    qreal distance = sqrt(pow(x - this->x(), 2) + pow(x - this->y(), 2));
    if (x - this->x() > 0)
        direct = RIGHT;
    else
        direct = LEFT;
    int timeLength = static_cast<int>(distance / speed);
    if (timeLine)
        delete timeLine;
    timeLine = new QTimeLine(timeLength);
    timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
    animation->setTimeLine(timeLine);
    animation->setTranslationAt(1, x - this->x(), y - this->y());
    timeLine->start();
    */
    if (state != MOVE)
        return;
    if (x - this->x() > 0)
        direct = RIGHT;
    else
        direct = LEFT;
    int dx = static_cast<int>(this->x() + (x - this->x()) * speed * 0.1);
    int dy = static_cast<int>(this->y() + (y - this->y()) * speed * 0.1);
    this->setPos(QPointF(dx, dy));
}