2D Toolkit Forum
2D Toolkit => Support => Topic started by: Bennett on April 15, 2012, 05:44:02 pm
-
I'm generating prefab animated sprites at runTime, and selecting an animation after instantiating them. But they all default to the collider set for frame 0. How can I get it to update the colliders as the frames change?
-
You need to set up the colliders on all the frames. If you have 1.60 (if you don't, you should upgrade, the editor is very much improved), simply shift select all your sprites, change the collider type, click Apply (to apply the change to all sprites) and Commit your changes.
-
I had already done that. The issue is that it doesn't update the collider at runtime.
And now I have an even worse issue, which is that I can't change the animation at all at runtime :-/
Not sure if it's a bug - I don't think I changed anything!
I'm calling it as follows (My animations are named "0", "1", "2", etc., and all the animated sprites are stored in an array called "_sprites"):
for (var i : int = 0;i < _sprites.length; i++) {
var anim:int = Random.Range(0,4);
_sprites[i].GetComponent(tk2dAnimatedSprite).Play( anim.ToString() );
}
-
Would it be possible to send me a test case? If so, please use support at unikronsoftware dot com. Otherwise, I will need a bit more info on what's going on and how things are set up.
-
I got it working by making a new SpriteAnimation object. I guess the old one got corrupted.
-
If this ever happens again, could you save a test case out for me please? Those files should never get corrupted (unless metadata is lost, but you'd have a lot more to worry about than just this if that happened)
-
Sure.
-
Sorry, I misread this question altogether. The polygon collider can't update in an animation. Doing so will require recreating the MeshCollider component every frame, which is really really slow.
-
Ok. But in the file I sent you, I'm also finding it impossible to change between animations using script.
I'm calling myTransform.GetComponent(tk2dAnimatedSprite).Play("animationName") but nothing happens. What am I doing wrong?
-
I'll look at that shortly, and get in touch by mail if I need further info