EDIT: What is further down below can kind of be made to work; however, I found a much better way in an example from a Level Director example project. Basically you just use the get and set linear velocity within the enterframe listener. I would strongly suggest downloading Level Director and reviewing the example projects (scroller2). There is a free option but the $19 is well worth it for the Full Edition. I haven’t seen any other examples of 2D platformers that have un-buggy movement.
The basic idea:
local vx,vy = player:getLinearVelocity()
-EXTRA CODE TO HANDEL DE-ACCELERATION-
vx= dx
player:setLinearVelocity(vx,vy)
Where dx is controlled by the left/right buttons. This does not seem to over-ride physics like some options do; the only thing I found is that I needed to remove friction from the player so that he would not levitate when pushing physics objects.
ORIGINAL POST (slightly buggy movement): The best I got was applyForce
e.g. player:applyForce(0, -1000, player.x, player.y) for jumping I think.
Lateral movement is more complicated. I had the right/left buttons toggle rightrun/leftrun variables on and then have the enterFrame event listener apply forces to the player.
I had to use an if statement to stop ‘applyForce’ from cummulatively making the player faster and faster.
e.g.
xVelocity, yVelocity = guy:getLinearVelocity()
if leftrun == true then
if xVelocity > -150 then
guy:applyForce(-100,0,guy.x,guy.y)
end
end
It is not perfect as movement is still slightly jerky; you can adjust it of course by modifying the threshold for applying the force; the movement seemed more jerky in the corona simlulator than it did on the actual device.
Hope that is some help; applyForce seemed better than other options I tried; this isn’t perfect but it is favourable to over-riding the physics engine for some games; I found options that gave smooth movement but over-rode the physics engine meant that the player could not interact normally with physics objects.
If you’ve found a better solution already I’d be keen to know. I am re-doing it at the moment so I’ll be keen to see if I can improve on it.