0

I was working on a pong game using python turtle. The ball that I am using python turtle is moving at random speeds. Sometimes it is too slow and sometimes it accelerates. I have no clue what is going on. This is the code that I have written for the pong ball -

ball = turtle.Turtle()
ball.speed(0)
ball.shape("square")
ball.color("white")
ball.penup()
ball.dx = 0.1
ball.dy = 0.1

while True:
window.update()
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)

I tried changing the dx and dy to a certain number to alter the speed but the ball rarely follows the command and is going too slow or fast.

  • 1
    This isn't a [mcve]--there's no movement here and `AttributeError: 'Turtle' object has no attribute 'dx'`. Did you subclass turtle? [I don't recommend that](https://stackoverflow.com/a/71003069/6243352). Please clarify. Thanks. – ggorlen Jan 06 '23 at 04:06
  • hello i do not understand anything that you have written, respectfully. – TupacShakur Jan 06 '23 at 15:36
  • For questions to be answerable, we need a [mcve] (please read that link). If you copy your code into an editor and run it, you'll see that turtle was never imported and it fails to run. I can infer that you have a `import turtle` at the top, no problem, but after adding that the code still crashes with the error I mentioned in my first comment. Turtles have no native `dx` attribute, and since that's not the error you're asking about in your question, there's no obvious leap of code I can think to add to fix it. So there's no path forward to helping you since I can't even run your code. – ggorlen Jan 06 '23 at 16:46

0 Answers0