Hi,
I'm trying to create a code that applies a force to the player body when mouse (or finger) is held down. Here's what I 've got, but it doesn't work:
function self:onMouseDown(event)
local mousedown = true
print("mousedown")
end
function self:onMouseUp(event)
local mousedown = false
print("mouseup")
end
function scene:onEnterFrame()
if mousedown == true then
self.ball.body:applyLinearImpulse(forcex, forcey , self.ball:getX(), self.ball:getY())
print("linearimpulse")
end
end
I'm having problems with the code inside onEnterFrame. Mousedown and mouseup events show up in the print output, but "linearimpulse" does not, so it clearly doesn't do anything. I'm probably missing something obvious, but maybe someone can point me into the right direction?
If I remove the whole "if" thing, the force is being applied correctly in every frame. However, I only want to apply it when the mouse is being held down.
Comments
Likes: Karriz
if you define it inside function, it is only for this function
if you define it simply in file, it is only for this file.
If you want something to be for the scene, then you must make it as a property of scene class, usually something like that: