Hello,
I'm trying to override the new function of a class that inherits the Sprite class, but I always get an error and I'm not sure why. Here is the code and the error:
Code:
Rectangle = Core.class(Sprite)
Rectangle.__new = Rectangle.new
Rectangle.new = function (x, y, width, height)
self = Rectangle.__new()
self:setX(x)
self:setY(y)
self:beginPath()
self:setLineStyle(2)
self:setFillStyle(Shape.SOLID, 0xFF0000)
self:moveTo(0,0)
self:lineTo(x,0)
self:lineTo(x,y)
self:lineto(0,y)
self:lineTo(0,0)
self:endPath()
return self
end
rect = Rectangle.new(50,50,100,100)
stage:addChild(rect) |
Error:
button.lua is uploading.
Uploading finished.
[string "property.lua"]:59: stack overflow
stack traceback:
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
...
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
[string "property.lua"]:59: in function '__new'
button.lua:8: in function 'new'
button.lua:25: in main chunk |
Thanks for help
cheers
David
Comments
Likes: dddent
Likes: dddent
I'll post the code, but due to some changes I made, its not working again, I'll post the error below, maybe s.o. can also help me with that:
about your last error then problem is that you define function with . and use it with :
So
self:drawbg() translates to self.drawbg(self) thus first parameter is always a table
All in all, this should work:
Likes: dddent