Problem:
I'm new to Defold but it's coming along. I am working on a hex tile game and I wanted to have different tiles represent sand, grass, and water. After updating my atlas file to include each tile graphic, I created a tile game object with logic to show or hide each sprite based on the passed in type.
Generating smaller maps I soon realized this was not going to work. Each tile game object had multiple sprites on it, and even though some were not visible, they still counted. In addition, any sprite decorations inside the tiles, but only showing up ever on one tile also counted.
Solution:
After playing around with the tint feature, I realized I could probably tint something white to be any color I wanted and anything dark or grey would still be visible (which is good because my tiles need outlines and I'm not going to build a shader for that...).
It worked really well. For each tile script I store the colors of each state, and tint the tile when I need it to change.
local water_color = vmath.vector4(.33, .66, 1, 1)
local sand_color = vmath.vector4(.99, .96, .62, 1)
local grass_color = vmath.vector4(.55, .79, 0, 1)
sprite.set_constant("#skin", "tint", grass_color)
Also, move any tile decorators outside the tile, make the tiles as simple as possible and that will help optimize your game.
No comments:
Post a Comment