Game Development Reference
In-Depth Information
f_nextTime = f_timePercent; //Update time by using frame
persecond
f_gridX = 1.0/in_gridX;
f_gridY = 1.0/in_gridY;
in_curFrame = 1;
}
public function updateAnimation (_direction : int, _material :
Material) : void {
//Update material
_material.mainTexture = spriteTexture;
//Update frame by time
if (Time.time>f_nextTime) {
f_nextTime = Time.time + f_timePercent;
in_curFrame++;
if (in_curFrame>in_framePerSec) {
in_curFrame = 1;
}
}
_material.mainTextureScale = new Vector2 (_direction * f_
gridX, f_gridY);
var in_col : int = 0;
if (in_gridY>1) {
//If there is more than one grid on the y-axis update the
texture
in_col= Mathf.Ceil(in_curFrame/in_gridX);
}
if (_direction == 1) { //Right
_material.mainTextureOffset = new Vector2(((in_curFrame)%in_
gridX) * f_gridX, in_col*f_gridY);
} else { //Left
//Flip Texture
_material.mainTextureOffset = new Vector2(((in_gridX + (in_
curFrame)%in_gridX)) * f_gridX, in_col*f_gridY);
}
}
public function resetFrame () :void {
in_curFrame = 1;
}
}
 
Search WWH ::




Custom Search