I'm having trouble getting my different sprites to cycle through correctly. If your movingdown then activate the first row of 3 sprites on the sheet. If your movingup then loop through only the 3 sprites in the second row only. I know it has something to do with the index.
var uvAnimationTileX = 3;
var uvAnimationTileY = 4;
var framesPerSecond = 10.0;
static var movingRight : boolean = false;
static var movingLeft : boolean = false;
static var movingUp : boolean = false;
static var movingDown : boolean = false;
function Update () {
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
if(movingDown) {
index = index % (3 * 1);
}
else if(movingUp) {
index = index % (3 * 2 );
}
else if(movingRight) {
index = index % (3 * 3);
}
else if(movingLeft) {
index = index % (3 * 4);
}
// Size of every tile
var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
asked
Apr 11 '12 at 03:58 AM
jessee03
306
●
58
●
77
●
89
Anyone know? I've tried a few forums and still no luck. Just trying to figure out how to loop through only one row depending on which direction a sprite is moving. The sprite sheet is 3 x 4 so if your moving one way loop through row 1 x3 if it's moving another way only loop through the second row of 3 and so on. Right now if it's 3x2 it will loop through the first two rows which I don't want.