Reputation: 367
I want to have multiple turtles for a game. turtle is the main character and monster is another turtle i've added. How to I add a shape to it. Heres the code:
import turtle
monster = turtle.Turtle()
monster.addshape('enemt.gif')
monster.shape('enemt.gif')
monster.goto(0, 0)
I get the error
Traceback (most recent call last):
File "C:\Users\Alfie\Desktop\Tutorial Game\Tutorial Game.py", line 77, in <module>
monster.addshape('enemt.gif')
AttributeError: 'Turtle' object has no attribute 'addshape'
Upvotes: 1
Views: 3354
Reputation: 41872
Rereading the documentation, addshape()
is listed as a method of turtle but the examples show it as a method of the screen, which works:
import turtle
screen = turtle.Screen()
screen.addshape('enemt.gif')
monster = turtle.Turtle('enemt.gif')
monster.goto(0, 0)
turtle.done()
Actually, turtle.addshape('enemt.gif')
also works in this code.
All methods of the Turtle class are also available as top level functions that operate on the default (unnamed) turtle instance. All methods of the Screen class are also available as top level functions that operate on the default (sole) screen instance.
Upvotes: 2
Reputation: 367
I found it, but I'll answer for anyone else with the problem :P
monster = turtle.Turtle()
monster.addshape('enemt.gif')
monster.goto(0, 0)
monster.shape('enemt.gif')
monster.addshape('enemt.gif') doesn't work because addshape is only for turtle, not multiple. Now if you use
turtle.addshape()
it works! But you use monster.shape()
sorry if I can't answer these questions, if anyone knows the actual reason that this works, edit this please :P
Upvotes: 0