Event listener for specific tile?

All things HTML5 or text based engines, or really any web based engines.
Post Reply
zaquanishak
Posts: 53
Joined: Mon Aug 26, 2013 1:54 am

Event listener for specific tile?

Post 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
zachz
Programmer
compass-interactive
robaldred
Posts: 64
Joined: Tue Aug 27, 2013 5:54 pm

Re: Event listener for specific tile?

Post 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
    }
  }
}
zaquanishak
Posts: 53
Joined: Mon Aug 26, 2013 1:54 am

Re: Event listener for specific tile?

Post by zaquanishak »

So how do i create for room changing? im not sure how to do it?

Regards,
Zachz
zachz
Programmer
compass-interactive
User avatar
coolbloke1324
Posts: 181
Joined: Mon Jan 23, 2012 5:20 pm

Re: Event listener for specific tile?

Post 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;
        }
    }
}
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
zaquanishak
Posts: 53
Joined: Mon Aug 26, 2013 1:54 am

Re: Event listener for specific tile?

Post by zaquanishak »

How do u use tileMap.map when using .loadJson() ? And can i extend the .loadJson() in to a class?

Regards,
Zachz
zachz
Programmer
compass-interactive
Post Reply

Return to “HTML5/Web Engines”