Sequence handler by speed

there’s a way to use a sprite listener that listen to the speed(physics) and swap sequences automatically?

for example: when speed is bigger than 5 - run…

Iv’e tried - if(speed > 5) then …:setSequence(“run”); …:play(); end but is doesent work…

any thoughts?

You would be better off using a timer or enterFrame to measure the velocity of the object and then change the animation based on that measurement.

The sprite listener is for sprite events only.

local obj = display.newSprite( ... your args ... ) physics.addBody( obj ) function obj.enterFrame( self ) local vx, vy = self:getLinearVelocity() local v = math.sqrt( vx \* vx + vy \* vy ) if( v \< 5 and self.sequence ~= "walk" ) then self:setSequence("walk") elseif( v \< 10 and self.sequence ~= "run" ) then self:setSequence("run") else -- do a default thing here end end Runtime:addEventListener( "enterFrame", obj )

Updated example above.  Not to use ‘enterFrame’ and check current sequence as well as velocity.

May not be exactly what you want, but should get you started.

You would be better off using a timer or enterFrame to measure the velocity of the object and then change the animation based on that measurement.

The sprite listener is for sprite events only.

local obj = display.newSprite( ... your args ... ) physics.addBody( obj ) function obj.enterFrame( self ) local vx, vy = self:getLinearVelocity() local v = math.sqrt( vx \* vx + vy \* vy ) if( v \< 5 and self.sequence ~= "walk" ) then self:setSequence("walk") elseif( v \< 10 and self.sequence ~= "run" ) then self:setSequence("run") else -- do a default thing here end end Runtime:addEventListener( "enterFrame", obj )

Updated example above.  Not to use ‘enterFrame’ and check current sequence as well as velocity.

May not be exactly what you want, but should get you started.