I am trying to move my object in the screen in all different direction corresponding to the arrow keys.
local mkbhd = display.newImageRect("MKBHD.jpg", 100, 100) mkbhd.x = ccx mkbhd.y = ccy physics.addBody( mkbhd, "dynamic", {bounce=0}) local function onKeyEvent(event) if ( event.keyName == "right" ) then mkbhd.x = mkbhd.x + 10 elseif ( event.keyName == "left" ) then mkbhd.x = mkbhd.x - 10 elseif ( event.keyName == "up") then mkbhd.y = mkbhd.y - 10 elseif ( event.keyName == "down" ) then mkbhd.y = mkbhd.y + 10 end end Runtime:addEventListener( "key", onKeyEvent )
It doesn’t work like I want it to. I don’t want to press the key repeatedly, but instead the object should move as I hold the key. I looked up online and found some stuff called enterFrame and applyLinearImpulse. Not sure if these would help me… If it does, how do I use it?
(…and don’t mind mkbhd :D. This is just a test. Im playin’ around…)