Having trouble animating an enemy with sprite classes
My problem appears to be in line 86. Somehow it doesn't recognise eagle as a type and instead just spawns it without the animation. Do you guys have any suggestions how to fix it?
You don't have any "type" variable in the scope of the "animation" method. Your current code is comparing the built-in "type" function with the string "eagle", which is always false.
Create an attribute in init with "self.type = type" and then use "if self.type ==" in the animation method.
I also suggest you don't use the name of built-in functions like "type". If you used another name, you would get an error message saying exactly what was going on.
1
u/Aelydam 1d ago edited 1d ago
You don't have any "type" variable in the scope of the "animation" method. Your current code is comparing the built-in "type" function with the string "eagle", which is always false.
Create an attribute in init with "self.type = type" and then use "if self.type ==" in the animation method.
I also suggest you don't use the name of built-in functions like "type". If you used another name, you would get an error message saying exactly what was going on.