I am trying to move only one sprite in a game loop including two sprites. I have included spr1
in the Bit.update()
method so if w is pressed spr1.y -= 60
. In other words the sprite is assigned to self
in the hope that only spr1
will be moved when w is pressed. However, in the current code, pressing w moves both spr1
and spr2
. How can I refer to and update only spr1
in the update method?
class Bit(games.Sprite):
def update(self):
if games.keyboard.is_pressed(games.K_w):
self = spr1
self.y -= 60
def main():
spr1_image = games.load_image("spr1.png")
spr1 = Bit(image = spr1_image,
x = games.screen.width / 10,
y = games.screen.height / 10)
spr2_image = games.load_image("spr2.png")
spr2 = Bit(image = spr2_image,
x = games.screen.width * 9 / 10,
y = games.screen.height * 9 / 10)
games.screen.add(spr1)
games.screen.add(spr2)
games.screen.mainloop()
main()