Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9106635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:23:05+00:00 2026-06-17T02:23:05+00:00

I’m making a 2D grid based game in Qt. When clicking on a square

  • 0

I’m making a 2D grid based game in Qt.

When clicking on a square in a grid the player moves to that square following a path calculated with an A* algoritm. However I would like to be able to animate this. So instead of immediately going to the goal the player has to go from square (node) to square until it reaches the goal at a speed that the user can set.

Question: What is the easiest way to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:23:07+00:00Added an answer on June 17, 2026 at 2:23 am

    Personally, I’d design this similar to the following:

    class Player : public QObject {
        ...
        QPoint pos;
        QList<QPoint> path;
        QPropertyAnimation posAnimation;
    };
    

    Define pos as a Q_PROPERTY. This enables you to use QPropertyAnimation to define an animation on this value for animating the movement between two adjacent points. After the animation is done, take() one point from the path and reconfigure the animation, giving you an animation along the whole path.

    Use a slot animationFinished() in the Player class to provide the next point to the animation.

    To start such an animation, fill the path with the values (in a function move(QList<QPoint> path) or similar), set the values of the animation and start it.

    These code snippets should help you:

    // in constructor:
    posAnimation.setPropertyName("pos");
    posAnimation.setTargetObject(this);
    connect(&posAnimation, SIGNAL(finished()), SLOT(animationFinished()));
    
    // in the slot:
    if(!path.empty()) {
        posAnimation.setStartValue(pos());
        posAnimation.setEndValue(path.takeFirst());
        posAnimation.start();
    }
    

    To define pos as a property, you have to define two slots: A reading and a writing function, also known as a getter and a setter:

    class Player : public QObject {
        Q_OBJECT
        Q_PROPERTY(QPoint pos READ pos WRITE setPos) // define meta-property "pos"
        ...
    public slots:
        QPoint pos() const; // getter
        void setPos(QPoint p); // setter
    private:
        QPoint m_pos; // private member
    };
    

    QPoint Player::pos() const {
        return m_pos;
    }
    void Player::setPos(QPoint pos) {
        m_pos = pos;
    }
    

    The Q_PROPERTY line just declares a meta-property. This has nothing to do with C++, but Qt’s meta object compiler parses this line and adds an entry to the internal property list. Then, you can say player->property("pos") to access the position instead of player->pos(). You may wonder why this is useful. It’s useful whenever you only want to pass around a property name as a string, like to tell the QPropertyAnimation which property to animate. Another scenario is when using scripting like QML. Then you define properties all over your classes. You can read more about meta-properties in the Qt documentation: The Property System.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.