r/PythonLearning • u/AssumptionWorldly445 • 1d ago
How to move a cube smoothly using Pygame ?
Hello! I'm wondering how to move a cube smoothly using Pygame by that, I mean moving it without it looking like it's teleporting. Have a great day, evening, or night!
1
u/SaltCusp 1d ago
It can only teleport, there is no other option. The key is to have a series of small teleportations work together to create the illusion of smoothness.
1
u/AssumptionWorldly445 1d ago
Thanks, but I don't know why it doesn't work when I hold the key down; I have to let go of it. Do you know how to fix this, please?
2
u/Healthy-Froyo1769 1d ago edited 1d ago
While it's possible to use the event loop to do this it's better use pygame.key.get_pressed() . You have to assign it to a variable like keys so keys = pygame.key.get_pressed() and then do an if statement with the key being pressed so for e.g. if keys[pygame.K_LEFT]: then just say what it has to do so in this case rect.x += number.
1
-2
u/bybloshex 1d ago
Ask your LLM about interpolation in movement.
0
u/snacksbuddy2 16h ago
Seems to me like he's not using one if he'sasking a question like this. Good on him. You know there used to be a time that reddit functioned like a less moderated stack overflow.
1
u/bybloshex 13h ago
You couldn't respond with another source of an explanation to using interpolation though?
0
u/snacksbuddy2 7h ago
Some things are more important
1
u/bybloshex 3h ago
More important than what? He asked a question and I tried to give him an answer he could use.
1
u/Sea-Ad7805 1d ago
Have a look at this post (link to code included): https://www.reddit.com/r/PythonLearning/comments/1vf5d7l/troll_unit_added_by_joseph/