SFML community forums

Help => Window => Topic started by: Phineas on August 12, 2020, 08:19:26 pm

Title: Move player like in Crossy Road
Post by: Phineas on August 12, 2020, 08:19:26 pm
I'm a beginner in SFML, and I want to create a top-down arcade game like Crossy Road (a simplified version that is) https://poki.com/en/g/crossy-road (https://poki.com/en/g/crossy-road).
In Crossy Road, you press/swipe once and the character move 1 tile, if you hold the key, nothing happen.
Soooo, I only know 1 way to do it: put it in pollEvent and setKeyRepeatEnabled(false)
   
        window.setKeyRepeatEnabled(false);
        //main loop
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if (event.type == sf::Event::KeyPressed) {
                        switch (event.key.code)
                        {
                        case sf::Keyboard::Left:
                                player.move(-100, 0);
                                break;
                        //right, up, down...
                        }
                }
        }
 
My question are:
1. Are there other ways?
2. In Crossy Road, the player "hop" to a new tile, how can I implement something like that (a simple move from 1 tile to another, not instant "teleport"), then I can add some moving animation to it.
Thank you!