I’m trying to add a simple Dpad style controller in my game. I have images for each button and want to add a function to move an object on the x and y axis on touch. What would be the best way to go about this. I’ve tried a few things and failed… Would a widget button be best or what?
I have this code below first that works when I touch the button… But if I try to use applyForce then I get an error. I’ll post the code and error below…
Error: (/Users/mkjt88/Library/Application Support/Corona Simulator/Scroller-0925D93CFA3CB11CBDED963F819C3755)
2013-01-29 17:00:41.591 Corona Simulator[21435:707] Runtime error
…ations/CoronaSDK/SampleCode/mkjt88/Scroller/test.lua:217: attempt to call method ‘applyForce’ (a nil value)
stack traceback:
[C]: in function ‘applyForce’
…ations/CoronaSDK/SampleCode/mkjt88/Scroller/test.lua:217: in function <…ations>
?: in function <?:229>
[lua]function btnUp:touch(event)
if event.phase == “began” then
iRocket.x = iRocket.x + 5
end
return true
end
btnUp:addEventListener(“touch”, btnUp)
function btnUp:touch(event)
if event.phase == “began” then
iRocket:applyForce(0, -15, iRocket.x, iRocket.y)
end
return true
end
btnUp:addEventListener(“touch”, btnUp)
[import]uid: 20272 topic_id: 35441 reply_id: 335441[/import] </…ations>
