x


specific sprite animation

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);

}
more ▼

asked Apr 11 '12 at 03:58 AM

jessee03 gravatar image

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.

May 03 '12 at 03:56 AM jessee03
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x59

asked: Apr 11 '12 at 03:58 AM

Seen: 433 times

Last Updated: May 03 '12 at 03:56 AM