Hello Guest

Author Topic: How to create a "night time mode" with tk2dtilemap  (Read 3961 times)

andrew2110

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
How to create a "night time mode" with tk2dtilemap
« on: December 02, 2014, 07:12:02 pm »
Hello all,

Am quite far through writing my game with tk2dtilemap - It's great, but now the artists I work with are trying to make me find a way to enable a night time mode. Just doing a simple overlay on the UI layer made things look darker, but without being able to add lights into the tilemap, it just looks like exactly what it is, an overlay placed on a tilemap.

I would like to attach a way of adding a light to the player, NPC's and some buildings so that they light the surrounding areas, but am pretty certain that this will absolutely ruin performance on mobile devices. Is there any way this can be achieved?



Here's how the tilemap looks at the moment. It's actually made up of two different tilemaps each with 4 layers on them (one for base tiles and another for the maps buildings and trees).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to create a "night time mode" with tk2dtilemap
« Reply #1 on: December 04, 2014, 10:05:21 am »
Yeah, don't add a light :)
Create a copy of the tk2d bshader, modify it so it takes a global tint color thats multiplied with the result.
            fixed4 col = tex2D(_MainTex, i.texcoord) * i.color * GlobalColor;

This tint color can be set from code (white = looks normal, dark blueish color = looks like nighttime). This will be pretty fast and efficient.

andrew2110

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to create a "night time mode" with tk2dtilemap
« Reply #2 on: December 05, 2014, 01:36:44 pm »
That does sound like a great way of doing it! I'm probably only about 6 months into getting to grips with Unity and this will be my first proper look at Shaders and the like, I don't seem to be able to find anything by the name of bshader, I note that the tilemap chunks use tk2d/BlendVertexColor as their shader so tried copying that but then wasn't sure how to add that bit of code to them, so figured I must be misunderstanding something.

Thank you for getting back to me, am excited to get this working!