Qt平移动画

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(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));
}

你可能感兴趣的:(Qt平移动画)