Game Development Reference
In-Depth Information
Step 6. Next you need to align the sprite walking direction with the
animations and use the pixel values entered into the Inspector to
display the correct animation sequence. To do this, a UV mapping code
similar to that used in previous examples will be used. When a different
arrow key is pressed, the animation sequence being displayed will
change. Modify SpriteManager.js as shown in Listing 3.20 .
Listing 3.20 Script to Manage Changing Animation States
of a Sprite
class spriteDetails
var pixelWidth: int;
var pixelHeight: int;
var singleSpriteDimensions: spriteDetails;
var idle: animFrame;
var walkleft: animFrame;
var walkright: animFrame;
var walkforward: animFrame;
var walkback: animFrame;
var currentAnimation = "";
var currentFrame = 0;
var currentStartFrame = 0;
var totalFrames = 0;
function Start()
function SetAnimation(animName : String)
if(currentAnimation == animName) return;
currentAnimation = animName;
if(currentAnimation == "WALK_LEFT")
currentFrame = walkleft.startFrame;
currentStartFrame = walkleft.startFrame;
totalFrames = walkleft.startFrame +
else if(currentAnimation == "WALK_RIGHT")
currentFrame = walkright.startFrame;
currentStartFrame = walkright.startFrame;
totalFrame s = walkright.startFrame +
Search Nedrilad ::

Custom Search