I'm trying to remove an object who is dragged inside a box but I'm having trouble understanding how to use these objects through my code. I'm getting used with Gideros and Lua. In Java, I could call my objects methods and do the verification and remove from the scene.
They way I'm trying to do is setting a global variable and when the onMouseUp is call in the box object I set the variable, but in my object Match, the event onMouseUp is no executing inside the box object. The hierarchy of the object could be the problem?
main.Lua
auxVar = false
function setValue(value)
auxVar = value
end
function getValue()
return auxVar
end
.
.
.
local teste = {1,1,1}
local teste2 = {2,2,2}
createMatchObj("box1", teste)
createMatchObj("box2", teste2)
createBox(25,350, "0xffbb15", "1") --box1
createBox(175,350, "0xa2bb15","2") -- box2 |
Match.lua
.
.
.
function Match:onMouseUp(event)
if self.isFocus then
self.isFocus = false
if getValue() then
print("Object released inside the box")
self:removeChild(self.downState)
end
event:stopPropagation()
end
end |
Box.lua
.
.
.
function Box:onMouseUp(event)
if self:hitTestPoint(event.x, event.y) then
--if self.isFocus then
--self.isFocus = false
if getValue == 0 then
setValue(true)
end
--end
--event:stopPropagation()
end
end |
English isn’t my first language, so please excuse any mistakes.
Comments
All Boxes and Matches are now subclasses of Shape and only Matches capture any mouse events. When creating a Match, it gets passed a table containing all of all boxes.
Whenever a Match receives a MouseUp event, it checks each box in the table and if it was released inside a box (and the box has the same id), then it removes its self from the stage (also removing the label, shape data, and event listeners).
I hope you can follow the example and find it of some use
Likes: Thuwiz
Thanks again.