Replace color vs new tiles

0 favourites
  • 7 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)