Hello Guest

Author Topic: Animated Tilemap Script  (Read 6267 times)

Kirb

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 36
    • View Profile
Animated Tilemap Script
« on: June 29, 2016, 03:56:13 am »
I was searching around for an easy method to allow for some very simple, 1-10 frame looping animations in a tileset in 2DTK.

I eventually came across this script, but despite me setting it up; it doesn't actually appear to work. https://gist.github.com/treefortress/2c9b034e696953bd83fc

It's a few years old; could it be using depreciated code or referring to 2DTK classes that no longer work? Has anyone else had luck using it?

Any help is appreciated.
« Last Edit: June 29, 2016, 08:49:46 pm by Kirb »

ComputerNerd

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Animated Tilemap Script
« Reply #1 on: June 29, 2016, 08:31:36 pm »
I am assuming your animations are inside of the tile set?  That's how this piece of code works.  You'd be pretty limited in options if that is the case.  Also keep in mind that the Build function will be slow if you are using tk2d colliders.

One way to skin this cat is to have the animation in a separate texture with its own material/shader, then reference the placeholder tile in the sprite collection with your new material.

An example and working shader you can use are here:
http://2dtoolkit.com/forum/index.php?topic=4529.0

You can also reference my topic here if you would like to use custom UV coordinates with that shader.

http://2dtoolkit.com/forum/index.php/topic,5362.0.html

Kirb

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Animated Tilemap Script
« Reply #2 on: June 29, 2016, 10:22:24 pm »
@ComputerNerd

Thanks a bunch for the tips! Using a shader does seem a bit easier to go about this task.

I have run into a few weird snags, though, as the animations are tilted 90 degrees when I paint them, and they also don't seem to be as wide as they should be.
Using the in-editor tool, I can correct the tilt, but they still seem squashed, resulting in the odd spaces of empty space between each tile as seen below.

http://i.imgur.com/2GS4g0n.png

I'm assuming your custom UV coordinates change would eliminate that, or is this problem something different?

EDIT:

Ah, found the cause! The placeholder sprite dimensions/transparency were influencing the animations. All fixed now, thanks for the help.




« Last Edit: June 30, 2016, 11:13:43 pm by Kirb »

ComputerNerd

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Animated Tilemap Script
« Reply #3 on: July 04, 2016, 05:43:56 pm »
That makes sense. Unless you use custom uv's like in my solution or something similar it will pass the original uv's for the Atlas to the shader.

nachobeard

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Animated Tilemap Script
« Reply #4 on: July 24, 2016, 11:48:58 am »
Hi

Do you know what the performance of this is like on mobile?

I'm concerned about the material count needed to achieve rich animation being too much for ipad 3 (which I'm targeting).
For that reason I'm leaning towards trying the spriteId swapping method linked to in the OP.

Any ideas or recommendations here?

thanks!
« Last Edit: July 24, 2016, 12:04:28 pm by nachobeard »

Kirb

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Animated Tilemap Script
« Reply #5 on: August 02, 2016, 03:13:59 am »
Hi

Do you know what the performance of this is like on mobile?

I'm concerned about the material count needed to achieve rich animation being too much for ipad 3 (which I'm targeting).
For that reason I'm leaning towards trying the spriteId swapping method linked to in the OP.

Any ideas or recommendations here?

thanks!

Not a clue as to the performance in mobile; but material count in the other method can definitely be a bit much.
If you manage to get the method I linked in the OP working; would you mind sharing how you did it?

ComputerNerd

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Animated Tilemap Script
« Reply #6 on: August 02, 2016, 05:50:57 am »
It basically comes down to this.  If you use the programmatic tile swapping method, you will need to have all of the frames of the animation inside of the sprite collection.  Whether that is ok or not is completely up to you and what your requirements are.

Another difference is the tile swapping is slightly more CPU intensive (since you have to call Build), while the shader method is slightly more GPU intensive.  You cannot use TileMap colliders with the tile swapping method due to the cost of rebuilding the colliders.  You cannot have dynamic actions take place on the shader method (an example being when the player steps on grass, switch the grass tile to "stepped").

From my experience, using the shader method, the GPU cost is negligible.  I am on a Surface 3 tablet and clock a very high FPS even with hundreds of animating tiles.

In the end, I use a mixture of both.  When the player steps on grass or cuts a bush, I use the tile swap.  When the animation is always running like fire or water, I use shaders.
« Last Edit: August 02, 2016, 05:11:27 pm by ComputerNerd »