Author Topic: FlxTilemap and FlxTile  (Read 1608 times)

magesauce

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
FlxTilemap and FlxTile
« on: Wed, Jun 17, 2015 »
Hello again!

I am messing around with FlxTilemap and I cannot figure out how to return a specific tile from a coordinate position. I can get the type with getTile(), but I am unable to actually access the tile. I need this because I am making a game where you are able to dig, which leads me to my next question.

Is there any way to add variables to a tile? For instance, in this case I want the tile to have some sort of life so when the player is holding down the mouse, it removes from the life and when the life is gone the tile is destroyed. I know I can do this by editing FlxTile, but I am hoping to find a way to do it without having to edit it. Thanks!

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: FlxTilemap and FlxTile
« Reply #1 on: Wed, Jun 17, 2015 »
Hello again!

I am messing around with FlxTilemap and I cannot figure out how to return a specific tile from a coordinate position. I can get the type with getTile(), but I am unable to actually access the tile. I need this because I am making a game where you are able to dig, which leads me to my next question.

Is there any way to add variables to a tile? For instance, in this case I want the tile to have some sort of life so when the player is holding down the mouse, it removes from the life and when the life is gone the tile is destroyed. I know I can do this by editing FlxTile, but I am hoping to find a way to do it without having to edit it. Thanks!

I don't believe FlxTileMap actually has specific tiles you can manipulate like that. I could be wrong though; I haven't worked with it much.

magesauce

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: FlxTilemap and FlxTile
« Reply #2 on: Wed, Jun 17, 2015 »
I just did something really tricky that I think works... so until someone tells me if there is an easier way I am just going to stick with this lol. I'll post it here to help anyone else out:

I basically just made two variables called previousTileX and previousTileY in my class and then set them and check if they are the same as the current tileX and tileY that the mouse is at. Here is it in action:

Code: [Select]
override public function update():Void
{
super.update();

FlxG.collide(_player, _world);

if (FlxG.mouse.pressed)
{
var mouseX:Int = Std.int(FlxG.mouse.x / TILE_WIDTH);
var mouseY:Int = Std.int(FlxG.mouse.y / TILE_HEIGHT);

if (Math.abs(FlxG.mouse.x - _player.x) < 250
&& Math.abs(FlxG.mouse.y - _player.y) < 250) {
if (mouseX == _previousTileX
&& mouseY == _previousTileY) {
_digTimer--;
if (_digTimer <= 0) {
_world.setTile(mouseX, mouseY, 0);
_digTimer = _digTime;
}
}
}

_previousTileX = mouseX;
_previousTileY = mouseY;
}
}