Page 1 of 1

Event listener for specific tile?

Posted: Tue Sep 03, 2013 11:50 am
by zaquanishak
Hi,

I would like to create something like a door that will bring my character to another map. How can i do this? Can i create a listener for specific tile in the tild2d? Thanks in advance.

Regards,
Zachz

Re: Event listener for specific tile?

Posted: Tue Sep 03, 2013 2:51 pm
by robaldred
You could use an IgeQuest, depending on your game you may, collect some stuff in a room then go to the exit, I'm not an expert with the engine with this looks like the most elegant solution. Take a look at example "9.6-quests"


Or you could just query the overTiles() method of your entity in it's tick callback. This will return an array of the tile points the entity is over.

This is completely untested but I'd imagine you could do something like...

Code: Select all

tick: function(ctx) {
 
  IgeEntity.prototype.tick.call(this,ctx)

  var tiles = this.overTiles()
  for(var i = 0; tiles.length; i++) {
    var tile_point = tiles[i]
    if((tile_point.x == doorX) && (tile_point.y == doorY)) {
      //trigger room change
    }
  }
}

Re: Event listener for specific tile?

Posted: Wed Sep 04, 2013 6:51 am
by zaquanishak
So how do i create for room changing? im not sure how to do it?

Regards,
Zachz

Re: Event listener for specific tile?

Posted: Wed Sep 04, 2013 6:09 pm
by coolbloke1324
What I would do is store a bit of trigger data on the tiles you want to go to different rooms, then check each tick if your player is over one of those tiles.

You can access the underlying Tile Map's IgeMap2d instance via the tileMap.map object. The data method of that object takes three parameters to set data (x, y, data) and two to read data (x, y).

You can assign data to a tile like this:

Code: Select all

tileMap.map.data(2, 3, {actionType: 'roomPortal', actionData: {roomId: 13}});
Then check the position of your player on the tile map and retrieve data for the tile via:

Code: Select all

var tilePoints = entity.overTiles(),
    tilePointCount = tilePoints.length,
    tileData,
    i,
    tileMapMap = tileMap.map;

// Loop the tile points and check if we are over a room portal
for (i = 0; i < tilePointCount; i++) {
    tileData = tileMapMap.data(tilePoints[i].x, tilePoints[i].y);
    if (tileData) {
        switch (tileData.actionType) {
            case 'roomPortal':
                var roomId = tileData.actionData.roomId;
                // Do what you want with moving player to new room
                break;
        }
    }
}

Re: Event listener for specific tile?

Posted: Tue Sep 10, 2013 7:07 am
by zaquanishak
How do u use tileMap.map when using .loadJson() ? And can i extend the .loadJson() in to a class?

Regards,
Zachz