Tiles
As you should know you can add tiles to rooms. A tile is a part of a background resource. Tiles are just visible images. They do not react to events and they do not generate collisions. As a result, tiles are handled a lot faster than objects. Anything that does not need events or collisions can best be done through tiles. Also, often one better uses a tile for the nice graphics while a simple object is used to generate the collision events.You actually have more control over tiles than you might think. You can add them when designing the room but you can also add them during the running of the game. You can change their position, and even scale them or make them partially transparent. A tile has the following properties:
- background. The background resource from which the tile is taken.
- left, top, width, height. The part of the background that is used.
- x,y. The position of the top left corner of the tile in the room.
- depth. The depth of the tile. You can choose any depth you like, making tiles appear between object instances.
- visible. Whether the tile is visible.
- xscale, yscale. Each tile can be drawn scaled (default is 1).
- blend. A blending color used when drawing the tile.
- alpha. An alpha value indicating tile transparency. 1 = not transparent, 0 = fully transparent.
The following functions exist that deal with tiles:
tile_add(background,left,top,width,height,x,y,depth) Adds a new tile to the room with the indicated values (see above for their meaning). The function returns the id of the tile that can be used later on.
tile_delete(id) Deletes the tile with the given id.
tile_exists(id) Returns whether a tile with the given id exists.
tile_get_x(id) Returns the x-position of the tile with the given id.
tile_get_y(id) Returns the y-position of the tile with the given id.
tile_get_left(id) Returns the left value of the tile with the given id.
tile_get_top(id) Returns the top value of the tile with the given id.
tile_get_width(id) Returns the width of the tile with the given id.
tile_get_height(id) Returns the height of the tile with the given id.
tile_get_depth(id) Returns the depth of the tile with the given id.
tile_get_visible(id) Returns whether the tile with the given id is visible.
tile_get_xscale(id) Returns the xscale of the tile with the given id.
tile_get_yscale(id) Returns the yscale of the tile with the given id.
tile_get_background(id) Returns the background of the tile with the given id.
tile_get_blend(id) Returns the blending color of the tile with the given id.
tile_get_alpha(id) Returns the alpha value of the tile with the given id.
tile_set_position(id,x,y) Sets the position of the tile with the given id.
tile_set_region(id,left,top,width,height) Sets the region of the tile with the given id in its background.
tile_set_background(id,background) Sets the background for the tile with the given id.
tile_set_visible(id,visible) Sets whether the tile with the given id is visible.
tile_set_depth(id,depth) Sets the depth of the tile with the given id.
tile_set_scale(id,xscale,yscale) Sets the scaling of the tile with the given id.
tile_set_blend(id,color) Sets the blending color of the tile with the given id. Only available in the Pro Edition!
tile_set_alpha(id,alpha) Sets the alpha value of the tile with the given id.
The following functions deal with layers of tiles, that is, collections of tiles at the same depth.
tile_layer_hide(depth) Hides all tiles at the indicated depth layer.
tile_layer_show(depth) Shows all tiles at the indicated depth layer.
tile_layer_delete(depth) Deletes all tiles at the indicated depth layer.
tile_layer_shift(depth,x,y) Shifts all tiles at the indicated depth layer over the vector x,y. Can be used to create scrolling layers of tiles.
tile_layer_find(depth,x,y) Returns the id of the tile with the given depth at position (x,y). When no tile exists at the position -1 is returned. When multiple tiles with the given depth exist at the position the first one is returned.
tile_layer_delete_at(depth,x,y) Deletes the tile with the given depth at position (x,y). When multiple tiles with the given depth exist at the position they are all deleted.
tile_layer_depth(depth,newdepth) Changes the depth of all tiles at the indicated depth to the new depth. With this function you can move whole tile layers to a new depth.