Change animation based on direction?

I’m looking for a way to change the current animation based on the direction the player is moving. What I’ve done so far is use sprite.newSpriteSheet and sprite.newSpriteSet to create animations for each directino as follows:

local frontwalkAnim = sprite.newSpriteSheet("front-walkanim.png", 32, 32);  
local frontSet = sprite.newSpriteSet( frontwalkAnim, 1, 3 );  
sprite.add( frontSet, "frontwalk", 1, 3, 1000, -2 );  

Then with this I’ll create the initial player icon using the following:

local playericon = sprite.newSprite( frontSet );  
playericon.x = 72;  
playericon.y = 151;  
playericon:prepare("frontwalk");  
physics.addBody( playericon, "dynamic", { density=2.0, friction=0.5, bounce=0.2, radius=16 } )  

The part I’m getting stuck on is how to change the sprite animation for playericon to either backSet, rightSet, or leftSet depending on the direction the player is moving. [import]uid: 38084 topic_id: 6652 reply_id: 306652[/import]