Turtle Long Press Lag - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: Turtle Long Press Lag (/thread-26856.html) |
Turtle Long Press Lag - Jimmy_Py - May-16-2020 Below is some code from a tutorial for making pong with Turtle. I noticed that the short presses of "w" and "s" move the left paddle instantaneously, whereas there is a 1 second delay for the paddle to move when I long press (or hold down one of the keys). Is there a way to make long press responses equally fast, or is it just something that has to be accepted with using Turtle? #Jimmy. 5-13-20 Pong, base on tutorial by Christian Thompson #His twitter is @TokyoEdTech import turtle wn = turtle.Screen() wn = turtle.Screen() wn.title("Pong by Jimmy") wn.bgcolor("black") wn.setup(width=800, height=600) wn.tracer(0) # stops window from update, requiring manual update. # Paddle A paddle_a = turtle.Turtle() paddle_a.speed(0) # sets animation speed to maximum. paddle_a.shape("square") paddle_a.color("white") paddle_a.shapesize(stretch_wid=5, stretch_len =1) paddle_a.penup() #something to do with not drawing lines. (which Turtle object do by default). paddle_a.goto(-350,0) # Paddle B paddle_b = turtle.Turtle() paddle_b.speed(0) # sets animation speed to maximum. paddle_b.shape("square") paddle_b.color("white") paddle_b.shapesize(stretch_wid=5, stretch_len =1) paddle_b.penup() #something to do with not drawing lines. (which Turtle object do by default). paddle_b.goto(350,0) # Ball ball = turtle.Turtle() ball.speed(0) # sets animation speed to maximum. ball.shape("square") ball.color("white") ball.penup() #something to do with not drawing lines. (which Turtle object do by default). ball.goto(0,0) # Functions def paddle_a_up(): y = paddle_a.ycor() y += 20 paddle_a.sety(y) def paddle_a_down(): y = paddle_a.ycor() y += -20 paddle_a.sety(y) def paddle_b_up(): y = paddle_b.ycor() y += 20 paddle_b.sety(y) def paddle_b_down(): y = paddle_a.ycor() y += -20 paddle_b.sety(y)[url=https://www.youtube.com/watch?v=DplYMapxi3Y]https://www.youtube.com/watch?v=DplYMapxi3Y[/url] # Keyboard Binding wn.listen() wn.onkeypress(paddle_a_up,"w") wn.onkeypress(paddle_a_down,"s") #Main game loop while True: wn.update() RE: Turtle Long Press Lag - deanhystad - Jun-05-2020 That is the key repeat delay, the delay between the initial key press and repeating the key press when a key is held down. It has nothing to do with Turtle. You can change the key repeat for your system, but it will affect all programs. RE: Turtle Long Press Lag - SheeppOSU - Jun-08-2020 You can go into the original Python files for turtle, find the code responsible, and change it, but then it will affect everything that you do with turtle. I suppose you could edit the original files to make a parameter for the wait, true or false. Then you just add a simple if statement. Also it would be best to make the parameter a default so that the function can still run without an extra argument being needed. RE: Turtle Long Press Lag - Jimmy_Py - Jun-13-2020 (Jun-05-2020, 01:10 AM)deanhystad Wrote: That is the key repeat delay, the delay between the initial key press and repeating the key press when a key is held down. It has nothing to do with Turtle. Interesting you say that, because I don't notice that same delay when I make similar games in pygame. Perhaps because I loop through the game loop in my pygame instance 60 times a second? RE: Turtle Long Press Lag - deanhystad - Jun-13-2020 Pygame probably binds key down/key up events and uses their own internal timer to get a better key-repeat for gaming. For typing you want the delay. |