Question

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.

Was it helpful?

Solution

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

  • 2D Toolkit, which by now also include a UI system
  • Orthello, of which there is a free version as well

OTHER TIPS

http://www.tasharen.com/forum/index.php?topic=2994.msg58298#msg58298

Hi,

Sprite Animation using NGUI: https://www.youtube.com/watch?v=ys60bEIa2zA

The video demonstrates the following:

  1. How to import a sprite sheet into NGUI
  2. How to import a Unity Sprite (Multiple mode) into NGUI
  3. Create animation clips (Sprite animations)
  4. Attach this animation clip to an NGUI sprite.

I hope this will be useful to you...

Thanks,

Vijay

dehinrsu@gmail.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top