Hi.
I've been trying to use OO in Gideros. So I created a "bubble" class from Bitmap as my sprite class, and created a local var "id" in the class.
I then used a for loop to generate an array of bubbles and stored an id to each bubble.
In the bubble class, when I called print(id) on touch/mouse event, it triggered every bubble's event function, and also returned the same id for every bubble.
Eg: (unnecessary code removed)
Bubble class:
GCbubble = gideros.class(Bitmap)
local myId = 0;
function GCbubble:onMouseDown(event)
print(myId);
end
Level Class:
function GClevel:setupLevel()
for i=1, cols*rows, 1 do
bubbleArray[i]=GCbubble.new(Texture.new("char.png"));
bubbleArray[i]:setId(i);
sceneCamera:addChild(bubbleArray[i]);
end
If the loop generates10 bubbles and I touch any 1 of them, i get "10" printed 10 times due to each bubble triggering the function.
Any way I can only make the touched bubble return its id?
Comments
Likes: arjunr24724
Just stumbled onto the soln myself (after scratching my head for the past couple of hrs), and your soln is exactly what I ended up doing =D>
Likes: ar2rsawseen
Likes: arjunr24724
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps