Replace color vs new tiles

Discussion and feedback on Construct 2

Post » Sat Jun 10, 2017 4:04 pm

I'd like to have a few variants of a tileset using different colors. I could use the replace color effect on the tilemap object 6 times (since it only has 6 colors) but i'm wondering how much of an impact this would have on performance and/or memory. Would it be better to have several copies of the tileset, each colored differently instead?
B
8
S
2
Posts: 18
Reputation: 611

Post » Sat Jun 10, 2017 5:34 pm

Don't use special effects to change the color, that's the worst thing you can do performance wise. Upload the tilemap 6 times each with different color.
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Sat Jun 10, 2017 5:51 pm

@Alpro you could also have one tileset that contains the different tile colour variants. If you need to change the colour during play then you can change the tile number for each tile using the "Set Tile" action in a nested loop.

e.g. tiles 0-3 are green, 4-7 blue, 8-11 red etc.

On event:

For "i" from 0 to tilemap.width,
For "j" from 0 to tilemap.height | tilemap: Set tile (loopindex("i"), loopindex ("j") to tilemap.TileAt(loopindex("i"),loopindex("j"))+4

When you run this it would go through each tile in the tilemap and add 4 to its number, shifting it to the complementary tile in the next colour set.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Sat Jun 10, 2017 6:18 pm

Thanks for the answers.

Yes, i'm considering having all the variants on the same tilemap and use index offsets as necessary. Speaking of this, if i have multiple tilesets, each with multiple variants, should i still go with a single large tilemap or use a tilemap for each set + all its variants?

At least for now, the game will show 3x3 rooms on the screen and some of these may use a different tileset. I was thinking of using 9 small tilemaps, even when they all use the same tileset, but with a single large one this would not be needed.

However, tilemaps with multiple tilesets means tiles not currently used are still in memory right? Not that this is a problem but you know, good programming habits... Less wasted memory if i go with one tilemap object for each tileset. I can always change them at runtime using JSON.
B
8
S
2
Posts: 18
Reputation: 611

Post » Sat Jun 10, 2017 6:20 pm

@Alpro here's a capx demonstrating it:

https://www.dropbox.com/s/yov4ovdjoigq1 ... .capx?dl=0

Press any key to cycle the colours.

I made a few changes to the original code I wrote above:

Adjusted the "i" and "j" loops to be one less than the width and height.
Added an extra check to prevent transparent tiles from being cycled.
Used the "%" modulo in the tile set action to ensure the colours cycled back around to red; the 16 figure at the end is the total number of tiles in the set.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Sat Jun 10, 2017 6:26 pm

@Alpro

Yes, if you are going to have layouts where a number of the variants aren't used then you'd be best off going for separate ones. Also, if you are going to have multiple colour variants on the same layout then it will most likely be easier to manipulate them if they are separate sets.

I think that cycling off a single set would be most beneficial if you were only displaying one colour variant at a time on a single map, e.g. night/day, different seasons etc.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Sat Jun 10, 2017 6:50 pm

@mekonbekon
Thanks for the example, simple enough.
Some screens will use multiple tilesets and/or variants, so i guess i will go with one tilemap per variant per set. I can make a simple function that copies the data from one tilemap object to another, then destroy the original, should tiles need to be changed dynamically.
B
8
S
2
Posts: 18
Reputation: 611


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 16 guests