How to fall my animation after it jumped?



  • Hi.in this program I have built a QPropertyanimation .and add my item and pos () property to it.
    I override KeyPressEvent.and with using of keys consist of "j,f,z" item go forward ,go back and jump.
    According gravity when item jump should fall down and returned previous its place .for this purpose i call down function .but item don't jump and don't fall. Please help me for this problem .thank you in advance.
    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    view=new QGraphicsView;
    scene=new QGraphicsScene;
    m=new MyQgraphicsObject;
    pr=new QPropertyAnimation(m,"pos");
    view->setScene(scene);
    view->resize(800,800);
    view->setFixedSize(800,800);
    setCentralWidget(view);
    scene->addItem(m);
    start= QPoint(0,0);
    }
    void MainWindow::keyPressEvent(QKeyEvent *k)
    {
    switch (k->key())
    {
    case Qt::Key_J:{

        forward();
        break;
    }
    case Qt::Key_Z:
    {
        up();
       //down();
        break;
    }
    case Qt::Key_F:
    {
        back();
         break;
    }
    default:
        break;
    }
    

    }
    void MainWindow::forward()
    {
    end.setX(m->pos().x()+50);
    pr->setEndValue(end);
    pr->setDuration(100);
    pr->setEasingCurve(QEasingCurve::Linear);
    pr->start();
    }
    void MainWindow::up()
    {
    end.setY(m->pos().y()-50);
    pr->setEndValue(end);
    pr->setDuration(100);
    pr->setEasingCurve(QEasingCurve::InQuad);
    pr->start();
    }
    void MainWindow::back()
    {
    end.setX(m->pos().x()-50);
    pr->setEndValue(end);
    pr->setDuration(100);
    pr->setEasingCurve(QEasingCurve::Linear);
    pr->start();
    }
    void MainWindow::down()
    {
    end.setY(m->pos().y()+50);
    pr->setEndValue(end);
    pr->setDuration(100);
    pr->setEasingCurve(QEasingCurve::InQuad);
    pr->start();
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.