How to use IgePoint?

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

How to use IgePoint?

Post by zaquanishak »

Hi,
I would like to know how can is use the IgePoint class in my character class? From the example u use it inside ServerNetworkEvent which i do not know where u declare it to retrieve the startTile position. Below is code from the example point to tile

Code: Select all

_onPlayerControlToTile: function (data, clientId) {
        if (ige.server.players[clientId]) {
            var playerEntity = ige.server.players[clientId],
                newPath,
                currentPosition = playerEntity._translate,
                startTile;

            console.log('Path to: ', data , 'From client: ', clientId);

            // Calculate the start tile from the current position by using the collision map
            // as a tile map (any map will do with the same tileWidth and height).
            startTile = playerEntity._parent.pointToTile(currentPosition.toIso());

            newPath = ige.server.pathFinder.aStar(ige.server.foregroundMap, startTile, new IgePoint(parseInt(data[0]), parseInt(data[1]), 0), function (tileData, tileX, tileY) {
                // If the map tile data is set to 1, don't allow a path along it
                // console.log('tileData', tileData);
                return tileData !== 1;
            }, true, false);

            playerEntity
                .path.clear()
                .path.add(newPath)
                .path.start();
        }
    }
What i want to do with this it to convert my tiles cordinate to iso, which i need the point method toIso(). But i do not know how to initiate it bcoz its not a component where i can add to my character class.

Please advice.

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

Re: How to use IgePoint?

Post by coolbloke1324 »

zaquanishak wrote:Hi,
I would like to know how can is use the IgePoint class in my character class? From the example u use it inside ServerNetworkEvent which i do not know where u declare it to retrieve the startTile position. Below is code from the example point to tile

Code: Select all

_onPlayerControlToTile: function (data, clientId) {
        if (ige.server.players[clientId]) {
            var playerEntity = ige.server.players[clientId],
                newPath,
                currentPosition = playerEntity._translate,
                startTile;

            console.log('Path to: ', data , 'From client: ', clientId);

            // Calculate the start tile from the current position by using the collision map
            // as a tile map (any map will do with the same tileWidth and height).
            startTile = playerEntity._parent.pointToTile(currentPosition.toIso());

            newPath = ige.server.pathFinder.aStar(ige.server.foregroundMap, startTile, new IgePoint(parseInt(data[0]), parseInt(data[1]), 0), function (tileData, tileX, tileY) {
                // If the map tile data is set to 1, don't allow a path along it
                // console.log('tileData', tileData);
                return tileData !== 1;
            }, true, false);

            playerEntity
                .path.clear()
                .path.add(newPath)
                .path.start();
        }
    }
What i want to do with this it to convert my tiles cordinate to iso, which i need the point method toIso(). But i do not know how to initiate it bcoz its not a component where i can add to my character class.

Please advice.

Regards,
Zachz
Hey dude,

The entity's _translate property is an IgePoint instance. That is how the code is working. You can see the declaration:

Code: Select all

currentPosition = playerEntity._translate
So currentPosition === playerEntity._translate which is an IgePoint. _translate holds the current "local" position of the entity - that is, the position of the entity relative to it's parent. Then we convert to iso and get the position of the tile the entity is over:

Code: Select all

startTile = playerEntity._parent.pointToTile(currentPosition.toIso());
If you break that line down, first the currentPosition is converted to an iso co-ordinate via:

Code: Select all

currentPosition.toIso()
Then that iso IgePoint is passed to pointToTile on the entity parent (which is a tilemap):

Code: Select all

playerEntity._parent.pointToTile(currentPosition.toIso());
The result is returned also as an IgePoint so "startTile" is an IgePoint as well.
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
zaquanishak
Posts: 53
Joined: Mon Aug 26, 2013 1:54 am

Re: How to use IgePoint?

Post by zaquanishak »

hi,
im aware of the ._translate can use the .iso() function. But how do i convert the overTiles() method to use the .iso() function too. Below are the code what im trying to do.

Code: Select all

 var tiles = this.overTiles(), playerReachDoor = false;
            var currentPosition = this._translate;
            //console.log('Current Position:--', currentPosition);


            this.occupyTile(tiles[0].x, tiles[0].y , 1 , 1);

                if((tiles[0].x === 1) && (tiles[0].y === 1)){
                playerReachDoor = true;
                if(playerReachDoor === true){
                    ige.network.send('goToDoor' , {id: this.id() , map:2});
                    playerReachDoor = false;
                }
above code are inside the characterContainer update method. What i try to do is when the character over a specific tiles it will occupy that tiles. But currently my this.overTiles() method is not converted to iso. So how do i convert it iso?
Untitled.png
Regards,
Zachz
zachz
Programmer
compass-interactive
zaquanishak
Posts: 53
Joined: Mon Aug 26, 2013 1:54 am

Re: How to use IgePoint?

Post by zaquanishak »

Hi,
Thanks i got it.

Code: Select all

 var tiles = this.overTiles(), playerReachDoor = false;

            var tilesIso = new IgePoint(tiles[0].x , tiles[0].y , 0).toIso();

            this.occupyTile(tilesIso.x, tilesIso.y , 1 , 1);
Regards,
zachz
Programmer
compass-interactive
Post Reply

Return to “HTML5/Web Engines”