Author Topic: Animations modifying images (spriteName)  (Read 2049 times)

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Animations modifying images (spriteName)
« on: September 08, 2014, 05:50:23 AM »
Hello.
I want to make an animation and modify the png with NGUI within the animation.
With pure Unity, I could add a SpriteRenderer script and then modify the sprites in the animation.
How should I procced with NGUI (and Unity 4.5)? In the Animation Window, I don't see any field to modify the spriteName. I'm using UI2Dsprites with Atlases and I want to make the typical animation based on an Atlas with 10 pngs moving my character.

Thank you.
Game developer on Casual Arena.

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Re: Animations modifying images (spriteName)
« Reply #1 on: September 08, 2014, 07:49:52 AM »
you need to use the UI2DSpriteAnimation and set your desired frames on the array here:


Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Re: Animations modifying images (spriteName)
« Reply #2 on: September 08, 2014, 08:38:24 AM »
Your image appears broken.
I have tried this script and I don't know how to use it, and I don't find any full example.
Game developer on Casual Arena.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animations modifying images (spriteName)
« Reply #3 on: September 08, 2014, 10:27:43 PM »
Ability to change sprite references via an animation is a special functionality available only to the Unity's SpriteRenderer.

To do it via NGUI you need to use UI2DSpriteAnimation or a custom script. UI2DSpriteAnimation is a good example of how you can switch sprites. Choose the sprites in a proper order, and the script will swap the UI2DSprite's sprites accordingly.

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Re: Animations modifying images (spriteName)
« Reply #4 on: September 09, 2014, 02:05:42 AM »
Thank you ArenMook.
Should I use SpriteRenderer from Unity or should I avoid mixing both NGUI and native-Unity?, ie, should I use NGUI animation or Unity animation?
Game developer on Casual Arena.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animations modifying images (spriteName)
« Reply #5 on: September 10, 2014, 12:40:10 AM »
Depends on the complexity of what you're doing. If things won't change much, NGUI will have an edge. If things will change every frame, Unity's 2D stuff will likely have an edge. If you just want a simple animation, use UI2DSpriteAnimation or your own custom logic. If you want complex animations, you'll likely be better off with Unity's 2D stuff.