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

Author Topic: How to move shape?  (Read 1115 times)

0 Members and 1 Guest are viewing this topic.

majkelolo

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to move shape?
« on: August 30, 2017, 08:49:11 pm »
My shape doesn't want move. When I press left or right arrow, it tells me that the key was pressed, but shape is still in his starting position.

Code: https://pastebin.com/4zycNNVh

Hapax

  • Hero Member
  • *****
  • Posts: 3370
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to move shape?
« Reply #1 on: August 30, 2017, 09:23:57 pm »
Should you not be setting "leftIsPressed" to false if it isn't pressed, same for right. Are they being initialised? Chances are that they are randomly being assigned true (anything but zero) if not.

You don't actually need these booleans as they serve the same purpose as isKeyPressed (you can use that directly in playerControl). However, if you still want to use them, assign them directly thus:
leftIsPressed = sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
rightIsPressed = sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
If you want them to be exclusive, you can simply add:
if (leftIsPressed)
    rightIsPressed = false;
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*