Hello,
I have some code (a function) that i want to add in a button/collision. But can't seem to make it work, does any one know how? I want to press a button, then the function is activated and working. Same thing with the collision.
Thanks a lot for your help!
Code that i want to add in a collision and a button:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | --The function i want to add: local function clearLines(event) for i = 1, #rectangle_hit, 1 do rectangle_hit[i]:removeSelf() rectangle_hit[i] = nil end end Button Code: local button2Press = function( event ) -- Adding the function in the button didn't seem to work? end local drop1 = ui.newButton{ default = "drop.png", over = "drop.png", onPress = button2Press, emboss = true } drop1.x = display.contentWidth/14 drop1.y = display.contentHeight/1.1 drop1.rotation = -90 -- Collision code: ball.myName = "ball" snow.myName = "snow" ball:addEventListener("collision", ball) function ball:collision (event) if event.other.myName == "snow" then -- I want to add the function in the collision ...? end end |
for a button its basic stuff:
1 2 3 4 5 6 7 | local function button2Press(event) if event.phase == "ended" then clearLines() end end button2:addEventListener("touch", button2Press) |
views:1411 update:2011/9/27 18:14:54