Stop sprite from playing (walking) when in the air (flying)

I have a sprite sheet of a man walking that I move (walk) with left/right buttons
I have another up button to make the object (instance of the sprite) fly
I can pause the sprite when left/right is released but when it’s flying and I hit left/right the sprite
keeps playing (walking) in the air is there a way to stop that and only play when on solid ground. [import]uid: 43696 topic_id: 10666 reply_id: 310666[/import]

Here’s how I’m currently checking to see if the player is in the air or standing on the ground (I found this in another tread):

 local function grounded()  
 local vx  
 local vy  
 vx, vy = player:getLinearVelocity()  
 return ( vy == 0 )  
 end  

For the above to work, you have to make your character fly via physics (eg. applyLinearImpulse()) and not by simply moving the transform.

To check whether or not the player is “grounded”, do something like this:

if grounded() then  
 --play walk animations  
else  
 -- play fly animations  
end  

[import]uid: 48658 topic_id: 10666 reply_id: 38722[/import]

–removed [import]uid: 43696 topic_id: 10666 reply_id: 38725[/import]

are you using physics ?

if not using physics, you can set a variable when you press the up button and on the left and right button event play the sequence only when the variable is not set. [import]uid: 71210 topic_id: 10666 reply_id: 50136[/import]

I am using physics. The “up” is only pressed to give a vertical boost to the player on “release” so the button can be released with the player still in the air and moving left and right
[lua]–moving on x-axis
local xaxis = function( event )
if player.x == nil then return true end
if event.joyX ~= false then player.x = player.x + event.joyX * maxSpeed
player:setLinearVelocity( 1, 0 )
if event.joyX > 0 then player.xScale = 1
elseif event.joyX < 0 then player.xScale = -1
end
end
end --end of xaxis

–moving on y-axis

local yaxis = function( event )
local onFlyTouch = function( event )
if player.y == nil then return true end
if event.phase == “release” and flyBtn.isActive then
player:applyLinearImpulse(0, -0.10, player.x, player.y)
end
end
flyBtn = ui.newButton
{
defaultSrc = “images/buttons/joystickYaxis.png”,
defaultX = 60,
defaultY = 60,
overSrc = “images/buttons/joystickYaxis.png”,
overX = 60,
overY = 60,
onEvent = onFlyTouch,
id = “FlyingButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
flyBtn.x = 440; flyBtn.y = 287
flyBtn.isVisible = false
flyBtn.alpha = 0.5

levelGroup:insert( flyBtn )
timer.performWithDelay( 200, function() flyBtn.isVisible = true; end, 1 )
end --end of yaxis [import]uid: 43696 topic_id: 10666 reply_id: 50229[/import]