Python Forum
[PyGame] Rectangle keeps teleporting?
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Rectangle keeps teleporting?
#2
I apologize if the formatting on this isn't 100% correct, this is my first post.

(Jun-25-2018, 08:41 PM)keyfive Wrote:
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                    playerStartingx += 0

You can make your code simpler by taking this out. I think you thought this was speed: If the key is down, you wanted the object going 50 pixels / frame and if the key is released the object goes 0 pixels / frame. However in your code, you are changing the position each time a key is pressed. The object will move +-50 pixels if a key is pressed down and 0 pixels if the key is up. <<< and this is why you don't need this part of the code, because the object won't move anyway.

When I tested the changes, the block still jumps but it is smoother. I suspect it has to do something with the for loop going through events. I think when a key is pressed it adds an event so the list just keeps getting longer. That's just a guess though because I don't have any experience with pygame.

Hopefully this will help you find that bug!
Reply


Messages In This Thread
Rectangle keeps teleporting? - by keyfive - Jun-25-2018, 08:41 PM
RE: Rectangle keeps teleporting? - by sonnekrieger7 - Jun-27-2018, 11:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Surface and rectangle in pygame Fabrizio_fg 6 2,311 May-27-2023, 09:15 AM
Last Post: Fabrizio_fg
  player just randomly teleporting to the edge of a platform in pygame BliepMonster 5 2,312 Jan-26-2023, 10:12 PM
Last Post: deanhystad
  Rotating a rectangle CompleteNewb 19 13,313 Aug-28-2021, 03:23 PM
Last Post: CompleteNewb
  Make rectangle snap to other rectangle corners Pedroski55 2 4,369 Aug-13-2021, 09:59 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020