Hello Guest

Author Topic: Using Mask on Crates  (Read 3296 times)

Gizmmo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Using Mask on Crates
« on: December 07, 2013, 03:55:38 am »
Hi!  I just started using 2D Toolkit, and Unity in general, and I was going through the tutorial found here: http://www.unikronsoftware.com/2dtoolkit/doc/2.2/tilemap/tutorial.html

First off it was awesome, and I'm super pumped to be working with 2D Toolkit.  I just wanted to ask though I notice after the Crates are changed to prefabs at the end, and then painted on I notice while in the TileMap Edit section when I'm painting, the crates are correctly shaded by the "light" color and "dark" color to give the appearance of a light, as they should be, but when the game is run all the crates turn back to their fully "lit" forms. 

I notice at the end of the tutorial you guys have the same thing too, which is nice cause it means i didn't mix something up half way through :P  Is there a way to change this so that the boxes are masked correctly, and could I get an explanation why this is happening if it's okay?  Thanks for the help guys, and again thanks for all your hard work!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using Mask on Crates
« Reply #1 on: December 07, 2013, 03:06:29 pm »
The tile map system builds a large mesh with the vertex colours in there. This colour grid is applied to the final tile map mesh when you commit. When you create prefabs, they are not part of the tile map but totally independent gameObjects. Thats why they don't inherit the colour, its not possible without being intrusive (i.e. setting the colour of the sprite by force) but what happens when the sprite moves?

You can however write a script to pick up the colour of the tile map and attach it to your prefab. Its pretty straightforward, in Update do this:
tileMap.GetInterpolatedColorAtPosition(transform.position) and apply it to your sprite.color.

That will make the sprite look like its inheriting the colour of the tile map behind it.

Gizmmo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Using Mask on Crates
« Reply #2 on: December 15, 2013, 06:11:59 am »
Great thanks for the answer.  Sorry for not replying for so long, finishing finals up.  I'll try it out now!