- Home /
Sprite Manager
i have asprite sheet in which i need to move frames 1-11 only once while 12-17 in a loop till a user clicks on a button on the sprite..
i wrote a script which plays the sprite once and it is working fine but dont know how to implement the looping property. any help would be appriciated.
thanks in advance.
possibly you are looking for InvokeRepeating(), check the docs
FYI 2DToolkit (asset store) in very popular for this sort of thing. it makes it all totally automatic, you just click 'loop' etc.
possibly you are looking for InvokeRepeating(), check the docs
Answer by AlucardJay · Sep 18, 2012 at 07:32 PM
I would set up a state engine and a counter :
enum spriteState { Idle, FirstFrames, LoopFrames }
var spritePlayState : spriteState;
function Start()
{
// Set the state like this :
spritePlayState = spriteState.FirstFrames;
}
function Update()
{
switch( spritePlayState )
{
case spriteState.Idle :
Idle();
break;
case spriteState.FirstFrames :
FirstFrames();
break;
case spriteState.LoopFrames :
LoopFrames();
break;
}
}
function Idle()
{
// do nothing, or just play first frame
}
function FirstFrames()
{
// Use your play script here to cycle between frames 1 and 11
// from here you can also change states
if (Input.GetKeyDown(Keycode.Space))
{
spritePlayState = spriteState.LoopFrames;
}
// or instead change state when frame reached 11 =]
}
function LoopFrames()
{
// Use your play script here to cycle between frames 12 and 17
// then with another condition return to Idle state
// spritePlayState = spriteState.Idle;
}
This is probably too complex for what you are after, but anyway, here's a state engine =]
Thanks @$$anonymous$$ $$anonymous$$ay....!! i wrote the script myself and now its working fine...! Had to make some changes in the script..!
Thanks for your help anyways...!!