Reputation: 55
In my corona application, I have a character that can fly
during the gameplay. This is accomplished by touching a jump/fly button
. I have achieved this as:
local c=false -- Flag residing fly/jump button state
function up:touch(event)
if event.phase == "began"
c=true
elseif event.phase =="ended" then
c=false
end
end
function jump(event)
if c then
character:applyForce (0,-300, character.x, character.y)
end
end
up:addEventListener( "touch", up )
Runtime:addEventListener("enterFrame", jump)
Now I need to disable the button until the character reaches the ground again. For that, I've decided to check the character Y position on runtime, but don't know how to do that. I'm not sure whether this is the correct idea or not. If you have a better option then please suggest me that also.
Problem:
Now I want to check disable the jump button once pressed.
Upvotes: 0
Views: 1382
Reputation: 69
This does what you are asking
local objX, objY
local obj
--this runs every frame
local function onEnterFrame( event )
objX = obj.x
objY = obj.y
end
Runtime:addEventListener( "enterFrame", onEnterFrame )
And for the C++ part, I don't think you can do that, Corona's scripting is in Lua. read this to learn Lua
Upvotes: 2