Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Move player like in Crossy Road  (Read 2913 times)

0 Members and 1 Guest are viewing this topic.

Phineas

  • Guest
Move player like in Crossy Road
« 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.
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!
« Last Edit: August 12, 2020, 08:26:34 pm by Phineas »

 

anything