Hello. I am new in corona SDK. How to do character management on the keyboard? I use the following code:
Runtime:addEventListener("key", walkPerson);
I use the following code in the walkPerson function:
local function walkPerson(event) if (event.keyName == 'd' and event.phase == 'down') then person.x = person.x + 15 return true end if (event.keyName == 'a' and event.phase == 'down') then person.x = person.x - 15 return true end if (event.keyName == 'w' and event.phase == 'down') then person.y = person.y - 64 person:setLinearVelocity( 0, 128 ) return true end if (event.keyName == 's' and event.phase == 'down') then person:setLinearVelocity( 0, 32 ) return true end return false end
This code allows you to move the character 1 time. How do I move the character while the key is pressed?
Tried to do it through the cycle, but the program starts to get hung up.
Sorry for my English.