Legacy GM Making tiles vanish when the player touches them?

I'm trying to figure out how to make hidden areas behind tiles, if you go behind them they drop their alpha. I figured out how to do this for objects



but I figure it would be more efficient to use tiles, more variety that way, how do I do this? I don't mind if all the hidden tiles turn alpha.
 

TheouAegis

Member
Can there be multiple hidden areas on the screen at the same time? If no, then put all concealing tiles on a separate layer from the background tiles and just use tile_layer_hide() and tile_layer_show() to toggle that layer.
 

Mornedil

Member
Sounds like you need to gradually change the alpha of the tiles to do that.
You can get an array of all tiles placed at a specific depth with the tile_get_ids_at_depth function.
So you could loop through the overlay tiles and set their alpha

create event:
Code:
tile_target_alpha = 1;
tile_alpha = 1;
Step event:
Code:
if (tile_alpha != tile_target_alpha) {
    if (tile_alpha < tile_target_alpha) then tile_alpha = min(tile_alpha + 0.1, tile_target_alpha);
    else tile_alpha -= 0.1;

    var tiles = tile_get_ids_at_depth(-1000);
    for (var i = 0; i < array_length_1d(tiles); i++) {
        tile_set_alpha(tiles[i], tile_alpha);
    }
}
set tile_target_alpha to 0 to fade out the tiles, and set it to 1 to fade in the tiles.
 
Last edited:
I think that could work. but there's an error on that.

The documentation has code for draw_set_alpha. That I thought could give me what I need.

Code:
var tile;
 tile = tile_layer_find(-1000, mouse_x, mouse_y);
 if tile_get_alpha(tile) < 1
    {
    tile_set_alpha(tile, 1);
    }
But using it keeps giving me the error: tile does not exist.
 

Mornedil

Member
from the screenshot it looks like you already have something else named "tiles" (which is why it's in a red color), so you can't name a variable the same thing. change the name of the "tiles" variable on lines 5, 6 and 7, and it should work.

Code:
if (tile_alpha != tile_target_alpha) {
   if (tile_alpha < tile_target_alpha) then tile_alpha = min(tile_alpha + 0.1, tile_target_alpha);
    else tile_alpha -= 0.1;

    var woopdeedoo = tile_get_ids_at_depth(-1000);
    for (var i = 0; i < array_length_1d(woopdeedoo); i++) {
        tile_set_alpha(woopdeedoo[i], tile_alpha);
    }
}
pretty sure you don't have anything else named woopdeedoo, but you can change it to anything as long as it doesn't conflict with anything else.


Edit: I thought I might also explain why this would give you an error:
Code:
var tile;
 tile = tile_layer_find(-1000, mouse_x, mouse_y);
 if tile_get_alpha(tile) < 1
    {
    tile_set_alpha(tile, 1);
    }
If there is no tile underneath the mouse, the "tile_layer_find" function won't find any tile. So you would first need to check if the tile exists before trying to set it's alpha:

Code:
var tile;
tile = tile_layer_find(-1000, mouse_x, mouse_y);
if tile != -1 //this makes sure the function above actually returned a tile
    {
    if tile_get_alpha(tile) < 1
        {
         tile_set_alpha(tile, 1);
        }
    }
 
Last edited:
Top