In Unity3d, I got a GameObject with the UISprite component from the NGUI plugin. So I need to use an atlas with textures, to set the texture for the UISprite.
Now I want the UiSprite to be animated. The different frames are in a spritesheet within the atlas itself.
I learned that you can animate something with a spritesheet by changing the offset. My questions is, how can I set the offset for the current texture and not for the entire atlas? So far, I can only change the offset for the entire atlas.
Is there a possibility to het position of the textures from within the atlas or something and calculate the offset with that?
I don't know how to proceed on this. Any insights are appreciated.
You don't really need to do this manually. The approach depends a bit on the scenario you have. If you want to play an animation once or in a loop, just use a UISpriteAnimation component (Add Component > NGUI > UI > Sprite Animation).
This allows you to create a certain set of named and numbered sprites. Set the correct prefix, framerate and whether or not to loop, and you're good to go.
But even if you somehow want to control it manually, there is no need to directly work with offsets. By setting the spriteName
of a UISprite
, you can dynamically change the displayed sprite at runtime. So all you would have to set is the sprite's name, and NGUI will handle the rest.
If you're looking to do full-blown sprite animation, NGUI might not be the best choice. It is after all a GUI framework. Other options to look into would be tools such as