2D Toolkit Forum
2D Toolkit => Support => Topic started by: Khorino on February 27, 2013, 12:10:03 am
-
Hi guys, so, we have many small sprites so that we can mix many of them to create a platform. The thing is that many are irregular, so a box collider wouldn't work so well. So far, I'm using a mesh collider for those, but the problem starts when one platform has 6 sprites and 6 mesh colliders. Is there someway to avoid that so the performance wouldn't be affected?
-
If its really irregular, and the parts didn't move, why not use the static sprite batcher? It will merge all the colliders into one poly collider.
-
How can I do that?
-
Have you seen this?
http://unikronsoftware.com/2dtoolkit/doc/tutorial/using_the_static_sprite_batcher.html
-
I've tried to do that and one of the sprites went down in scale (back to 1) and the other one didn't. I redid the configuration and after that, it worked ok, but the problem is that both mesh colliders from both platatforms were still there.
Just to be clear: in the test I tried, I use 2 different sprites to create one single platform. It's like the sprites are "glued" together. In your example, each sprite appear to be one platform, but our assets are really small to do that.
Am I doing something wrong?
-
Yup, but when committed, the sprites should be merged - so you'll be dealing with one mesh collider instead of however many you would have had prior to the merge. Isn't that what you were looking to do?
-
Yes. After I press "Commit", the "Game" view still show both colliders (green lines). Is this normal? The colliders still merged but Unity doesn't show them like that?
-
Yes that is normal. The code doesn't physically merge geometry, but the colliders are "merged" as in there is only one meshcollider. Ideally you want to have as few mesh colliders as possible, so merging these should be hugely beneficial.
-
Ok, great! Thanks!
-
Hey, unikron, every time I press "Commit", the scale of children objects go back to 1. Is there a way to avoid that from happening?
-
The scale is baked in the tk2dSprite.scale parameter - that way it doesn't break batching. Using Unity's transform.scale will break batching. The sprites should appear at the correct size though, if they aren't then that's a bug.
-
Ok, one more thing: I use the bake scale from 2DTK on the children object. Works fine. But when I use on the main object, the children's position changes. Am I forgetting something?
Thanks for your patience!
-
Yeah, that is a bit of a complicated case. Scales as applied to transforms cascade (i.e. it is possible to create a skewed sprite by rotating and then scaling the parent). In some cases, you might find that the scale doesn't apply properly.
What is it specifically you're trying to do with the hierarchical scales and stuff? (Just curious - if it is something people tend to use frequently, I'll see if anything can be optimized further)
-
As I said before, I'm using small sprites to create platforms. For example, sprites 1 and 2 to create platform A.
So, sprite 1 is a game object and 2 is the children. Both would be used on the Static Sprite Batcher.
-
You're not scaling the static sprite batcher though are you? If not, then all cascaded scales which don't result in skewing will be respected
-
No, no. The scale problem is already fine. The only problem I'm facing now is when I press "Commit" and the children object (sprite 2) changes its position on the X axis.
-
Please send a simple repro case for this to support@unikronsoftware.com.
-
Ok, I'm trying to replicate the problem on a new project and scene... and I can't! It works fine there, but on my project and scene, it doesn't! How's that possible?
-
I'm not sure whats happening. Hard to say without seeing it. Can you do a screencast or something demonstrating whats happening? Same email address again.
-
E-mail is there! :)