Why does an error happen when I try to call the subclass of "SpriteNode"?
Here is the subclass of SpriteNode
def __setattr__(name, duration, from_brick): SpriteNode.__setattr__(name, duration, from_brick)
It actually must display a Powerup on the screen.
Don't worry about the from_brick.position attribute in the init function, the from_brick attribute of my class must be a SpriteNode.
Notice: I have done all the indents, but they may be not displayed, don't worry.
Here is how I call the class to create a Powerup:
pup = Powerup("plf:Item_Star", 30, brickOnScreen)
The brickOnScreen variable was defined.
Gives a TypeError, that init() takes 3 arguments, but 4 were given (The error bookmark points at the line where I assign the class to the pup variable.
Thanks for your answers, programmers!
@happy_variable try the following instead of
__init__ (self, name, dration, from_brick):
In python, class methods (except the staticmethods or classmethods) are called with the instance of the class as the first argument.
EDIT: You will also need to replace
SpriteNode.__setattr__(name, duration, from_brick)with
SpriteNode.__setattr__(self, name, duration, from_brick).
This is because
SpriteNode.__setattr__is a unbound class method.