Game Development Reference
In-Depth Information
//Update Walking animation while the character is walking
loopSprites[1].updateAnimation(in_direction, renderer.
material);
} else {
//Stay
//Reset Walking animation frame back to the first frame
loopSprites[1].resetFrame();
//Update Stay animation while the character is not walking
loopSprites[0].updateAnimation(in_direction, renderer.
material);
}
}
7. Then, we create a LateUpdate() funcion, which is called ater all the Update()
funcions have been called. We will use this funcion to update our camera posiion
ater our character movement by seing its transform to follow our character:
public function LateUpdate() : void {
//Update Main Camera
Camera.main.transform.position = new Vector3(transform.
position.x, transform.position.y, Camera.main.transform.
position.z);
}
8. Next, we create the SpriteManager class to manage our sprite texture in the
CharacterController_2D.js ile; coninue from our preceding script, and add
the following:
class SpriteManager {
public var spriteTexture : Texture2D; //Set Texture use for a
loop animation such as walking, stay, etc.
public var in_framePerSec : int; //Get frame per sec to
calculate time
public var in_gridX : int; //Get max number of Horizontal images
public var in_gridY : int; //Get max number of Vertical images
private var f_timePercent : float;
private var f_nextTime : float; //Update time by using frame
persecond
private var f_gridX : float;
private var f_gridY : float;
private var in_curFrame : int;
public function init () : void {
f_timePercent = 1.0/in_framePerSec;
 
Search WWH ::




Custom Search