Hello Guest

Author Topic: Commit sprites using StaticSpriteBatcher in runtime.  (Read 6695 times)

saygon

  • Newbie
  • *
  • Posts: 7
    • View Profile
Commit sprites using StaticSpriteBatcher in runtime.
« on: January 21, 2013, 11:49:23 am »
I have idea of game, where level created from small cubes.
I want to use 2d toolkit for this:
So, I have a lot of sprites from one sprite collection and I want to commit a bach of these sprites created in runtime.
So, the steps are follows:
1. Create sprites in runtime (I found on this forum how do to it).
2. Commit all sprites that attahced to different game objects using StaticSpriteBatcher.

Can I do it (step 2), using 2d toolkit, because in reference I can not found StaticSpriteBatch class?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Commit sprites using StaticSpriteBatcher in runtime.
« Reply #1 on: January 22, 2013, 11:36:28 am »
If you're creating a static sprite batcher at runtime, you don't need to follow the "create sprites", "commit" workflow. You can bypass all of that, making the whole process very efficient in code.

Steps to do this:
1. Create gameObject and add a tk2dStaticSpriteBatcher component
2. Assign staticSpriteBatcher.spriteCollection
3. Create an array of tk2dBatchedSprites and assign to staticSpriteBatcher.batchedSprites.
4. Call staticSpriteBatcher.Build()

Thats it. You should have a committed static sprite batcher by the end of this.

saygon

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Commit sprites using StaticSpriteBatcher in runtime.
« Reply #2 on: January 29, 2013, 10:49:14 am »
Thank you very much!

This approach works perfectly.

dpk

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Commit sprites using StaticSpriteBatcher in runtime.
« Reply #3 on: June 27, 2013, 09:03:42 pm »
Could you go in to more detail on these steps? I'm not sure what to do for step 2 and I'm unable to get this to work. I tried using the tk2dBaseSprite's spriteCollection, but no joy.

I've got an array of tk2dBatchedSprites (made using a set of instantiated GameObjects w/ tk2dSprite components and a copy of the editor's "FillBatchedSprite" static method) but the resulting static sprite batcher does not render anything until I click "Edit" and "Commit" while in runtime.

Should there be a step 5: Destroy all of the tk2dSprites created while creating the tk2dBatchedSprite array?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Commit sprites using StaticSpriteBatcher in runtime.
« Reply #4 on: June 27, 2013, 10:45:42 pm »
@dpk - you're not doing it right. There shouldn't be a step 5, there should be no tk2dSprites created at all?
Here is a sample:
http://unikronsoftware.com/2dtoolkit/doc/2.00/advanced/scripting_static_sprite_batcher.html

dpk

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Commit sprites using StaticSpriteBatcher in runtime.
« Reply #5 on: June 28, 2013, 12:56:46 am »
@unikronsoftware Ah ha, thanks, I appreciate the link. I think the main thing I was missing was how to use tk2dBatchedSprite. FillBatchedSprite does a lot of stuff but your DynamicCreateBatcher script looks like it does just what is necessary.