Hello Guest

Author Topic: Play Sprites in sync  (Read 3554 times)

Maserat

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Play Sprites in sync
« on: February 20, 2013, 05:06:54 am »
I am having an issue where I have two sprites played at the same time, but when I slow it down with the editor in step, I notice that the animations are off by one frame. It is seamless on the computer, but becomes obvious when pushed to an iOS device. Is there a way to play the animations at exactly the same time.

The animations are exactly the same in the editor when it comes to frame numbers, fps, etc. The only thing different is are the event frames.
I have simple code like.
Code: [Select]
void Start(){ sprite1.Play( "Run" ); sprite2.Play( "Run" ); }But instead of both updating on the same draw, I get frames where sprite1 is at frame 20 while sprite2 is at 21. It seems to always happen when changing clips during an event.

Thanks in advanced. This is literally my last hurtle with sprites in my game.
« Last Edit: February 20, 2013, 05:49:46 am by Maserat »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Play Sprites in sync
« Reply #1 on: February 22, 2013, 12:03:13 am »
Changing something during an event is tricky as update order isn't defined in Unity. Lets say you have 2 animsprites,
A and B,
and they update in that order.
In A's event you call Play on A and B, everything is fine, except that B will now get updated after its started playing the new clip.

Easy solution - instead of calling Play like this, set a flag on another class which will call Play deferred on both these sprites at the same time either at the end of the frame, or on the start of the next frame.

Hope that makes sense.