im trying to build a pong game but i cant get rid of a line
import turtle
sc = turtle.Screen()
sc.setup(width=1000, height=1000)
sc.title("pong")
sc.bgcolor("black")
def paddle_a():
paddle = turtle.Turtle()
paddle.color("white")
paddle.shape("square")
paddle.shapesize(stretch_wid=5, stretch_len=2)
paddle.goto(-400, 0)
paddle.speed(0)
paddle.penup()
def paddle_b():
pass
while True:
paddle_a()
sc.update()
ive tried turtle.turtlehide() but no luck
CodePudding user response:
The problem is that when you move turtle to (-400, 0)
, the pen is down, it will draw line. Solution is to move penup()
method before the movement.
def paddle_a():
paddle.penup() # <--- Move here
paddle.goto(-400, 0)
paddle.speed(0)
CodePudding user response:
You just needed to lift the pen up at the correct position (before the goto
).
I added a penup in the correct place for you (it is commented in the code below).
import turtle
sc = turtle.Screen()
sc.setup(width=1000, height=1000)
sc.title("pong")
sc.bgcolor("black")
def paddle_a():
paddle = turtle.Turtle()
paddle.color("white")
paddle.shape("square")
paddle.shapesize(stretch_wid=5, stretch_len=2)
paddle.penup() # <------------------------- added a penup here
paddle.goto(-400, 0)
paddle.speed(0)
paddle.penup()
def paddle_b():
pass
while True:
paddle_a()
sc.update()