Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle Long Press Lag
#1
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()
Reply


Messages In This Thread
Turtle Long Press Lag - by Jimmy_Py - May-16-2020, 01:52 AM
RE: Turtle Long Press Lag - by deanhystad - Jun-05-2020, 01:10 AM
RE: Turtle Long Press Lag - by Jimmy_Py - Jun-13-2020, 01:30 PM
RE: Turtle Long Press Lag - by SheeppOSU - Jun-08-2020, 04:38 PM
RE: Turtle Long Press Lag - by deanhystad - Jun-13-2020, 03:17 PM

Forum Jump:

User Panel Messages

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