Reputation: 618
In my program, in order to simulate movement, the x position of the dot is added to, the old dot is cleared, and a new one is drawn.
def drawing_zombies():
clear()
for zombie in zombies:
goto(zombie.x, zombie.y)
dot(20, 'red')
update()
def movement():
for zombie in zombies:
zombie.x -= 0.5
drawing_zombies()
I have seen an extremely similar program run, and its dot didn't flash, it looked like it was genuinely moving. However, when my program is run, it flashes (disappears and reappears extremely fast)
The rest of the code is below (aside from a bunch of things defining the vector class, which is the same as in the program that worked, so nothing inside of it could be the problem)
class vector(collections.abc.Sequence):
precision = 6
__slots__ = ('_x', '_y', '_hash')
def __init__(self, x, y):
self._hash = None
self._x = round(x, self.precision)
self._y = round(y, self.precision)
#The rest of the vector class would have been here
zombies = []
placement_options = [0, 1, 2, -1]
def new_zombie():
placement_level = random.choice(placement_options)
z = vector(200, placement_level*100)
print(placement_level)
zombies.append(z)
def drawing_zombies():
clear()
for zombie in zombies:
goto(zombie.x, zombie.y)
dot(20, 'red')
update()
def movement():
for zombie in zombies:
zombie.x -= 0.5
drawing_zombies()
for z in zombies:
if z.x < -200:
done()
ontimer(movement(), 50)
def gameplay():
setup(420, 420, 370, 0)
hideturtle()
up()
new_zombie()
movement()
done()
gameplay()
Upvotes: 0
Views: 74
Reputation: 13533
You can use the tracer(False)
function to disable screen updates. So basically, all the drawing is done in memory and will be copied to the screen all at once when you call tracer(True)
.
def drawing_zombies():
tracer(False)
clear()
for zombie in zombies:
goto(zombie.x, zombie.y)
dot(20, 'red')
update()
tracer(True)
Upvotes: 1