Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. How to fall my animation after it jumped?
Forum Updated to NodeBB v4.3 + New Features

How to fall my animation after it jumped?

Scheduled Pinned Locked Moved Qt in Education
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarina95
    wrote on last edited by
    #1

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

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved