So, I am making a tower defense game using Python's turtle module and I just started off. For some reason though, the .tracer at the very beginning is creating an extra turtle for me for some reason. I don't know why. I have 3 classes, and so far, I have only defined 4 sprites: Helper, Enemy, Enemy, Enemy. When I remove the tracer, the turtle suddenly disappears. I accessed my turtle list and started to delete them. That didn't work. Here is the code:
import turtle as t
import random as r
wn = t.Screen()
wn.tracer(0)
class Sprite():
def __init__(self, color, speed, shape, ento, x, y):
self.sprite = t.Turtle()
self.color = color
self.speed = speed
self.shape = shape
self.ento = ento
self.x = x
self.y = y
def render(self, pen):
pen.speed(0)
pen.color(self.color)
pen.shape(self.shape)
pen.up()
pen.goto(self.x, self.y)
class Helper(Sprite):
def __init__(self, color, speed, damage, shape, x, y):
self.sprite = Sprite(color, speed, shape, 'Helper', x, y)
self.helper = t.Turtle()
self.color = color
self.speed = speed
self.shape = shape
self.ento = 'Helper'
self.damage = damage
self.x = x
self.y = y
def fire(self):
pass
class Enemy(Sprite):
def __init__(self, color, speed, health, shape, x, y):
self.sprite = Sprite(color, speed, shape, 'Enemy', x, y)
self.enemy = t.Turtle()
self.color = color
self.speed = speed
self.shape = shape
self.ento = 'Enemy'
self.health = health
self.x = x
self.y = y
self.state = 'frozen'
self.tick = 0
def move(self):
if self.state == 'frozen':
self.state = 'moving'
self.tick = 0
self.enemy.forward(self.speed)
self.x = self.enemy.xcor()
self.y = self.enemy.ycor()
self.tick += 1
helpers = []
for i in range(1):
test = Helper('green', 1, 1, 'square', 0, 0)
enemies = []
for i in range(3):
enemies.append(Enemy('red', 1, 1, 'circle', r.randint(-100, 100), r.randint(-100, 100)))
print(wn._turtles)
while True:
wn.update()
test.render(test.helper)
for enemy in enemies:
enemy.render(enemy.enemy)
enemy.move()
Why is this not working. I work on a windows computer. I am not really sure if this applies to only me or to everyone.
question from:https://stackoverflow.com/questions/66064061/why-is-the-tracer-making-another-turtle-in-python