Game Development Reference
In-Depth Information
FIG 3.5 The created texture atlas.
Listing 3.4 Setting the Texture Offset and Scale to Display
the First Frame from the Walk Cycle Atlas
var textures: Texture2D[];
var atlas: Texture2D;
function Start()
totalWidth = textures[0].width *textures.length;
for(var i: int = 0; i < textures.length; i++)
renderer.material.mainTe xtureOffset = Vector2(0,0);
renderer.material.mainTextureScale =
Vector2 (1.0/textures.length,1);
Step 10. Play. The first frame will appear on the plane.
Step 11. Next, to animate the sprite, the frames need to change.
Changing each Update() would be erratic and too fast as the time
between Updates() is not fixed and depends on the processing occurring
in the game. We therefore need to implement a timer that can switch the
frames for us. Modify AnimatedSprite.js as shown in Listing 3.5 .
Search Nedrilad ::

Custom Search