Hello Guest

Author Topic: Combining static batched sprite edge colliders into 1 collider  (Read 4545 times)

arvz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
I'm using tk2dStaticSpriteBatcher to batch a bunch of 'block' object into a collection of block objects. It looks like this:



As you can see, this batched sprite is comprised of many edge colliders.

Due to the way some other parts of my game works I need the object to have just 1 edge collider surrounding just the 'actual' edges of the object, like this:



I made that collider myself, as you can see it's pretty rough and takes a long time to edit manually by shift-clicking the collider vertices into place.

I realise tk2d doesn't really have any feature to do this, but I was wondering if you might be able to suggest some options I could try?

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Combining static batched sprite edge colliders into 1 collider
« Reply #1 on: May 31, 2014, 07:02:19 pm »
The tk2d tilemap editor will perform this optimization, its worth a try to see if it'll do what you need.

arvz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Combining static batched sprite edge colliders into 1 collider
« Reply #2 on: June 01, 2014, 01:11:07 am »
I need to position/instantiate these dynamically on runtime though so I don't think the tilemap editor will work  for me in this case

edit: Just tested it, and the optimization does work. I still need to use the object in a non-tilemap manner though. Maybe I can just copy the edge collider it generates and just paste it into my object? This is still a lot of work as I'd have to make the objects twice (Once in the tilemap, and another just by placing them manually and batching them) Is there a better way?
« Last Edit: June 01, 2014, 02:01:14 am by arvz »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Combining static batched sprite edge colliders into 1 collider
« Reply #3 on: June 01, 2014, 06:44:16 pm »
Well you do have the code, you could simply get the code that optimizes the tilemap collider and apply it to the static sprite batcher collider - it'll be a bit of work, but if you need the functionality it will be the best way to go about it.
The relevant functions are tk2dStaticSpriteBatcher.BuildPhysicsMesh2D
and tk2dTileMapColliderBuilder2D  BuildForChunk - the code there is fairly well documented.