I read this related
post. But I haven't figured out how it works.
First, I have this base class "Item" (simple one)
Item = Core.class(Sprite)
function Item:init()
self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, self)
end |
It works perfectly.
Now I would like to create another class "SubItem"
SubItem = Core.class(Item)
function SubItem:init()
self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, self)
end |
I would like to have it behave such a way that, when it is touched, it is triggering the onTouchesBegin of the SubItem, but not the base class Item.
Now, from observation, it enters "
Both" - first from base class, then its own onTouchesBegin
Not sure I have missed out anything. Is that a way to override the base class function? (without calling its base class function)
P.S.: Sorry I missed out the point that it is a 'Constructor'.
Comments
e: stopPropagation ()
in the onTouchesBegin function
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Thanks for your response. Do you mean this? (Adding to both base and subclass).
Probably I miss out something... Or did I misunderstand .. When it "stopPropagation", does it mean it stop propagating to its base class?
Likes: newbie2018
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
it works~ thanks
I used to do initialization in the Constructor.
But those initialization always call the base class functions before those from subclass.
As an alternative, I need to have another function (eg: named as Setup()). This function would override the base one without calling the base contents...
add a minor delay... LOL