Jump to content

Placing Enemies on a tilemap


codevinsky
 Share

Recommended Posts

please elaborate..  how do you get the GID ?   i for myself am counting the tiles in my tileset image to get to the GID..    

 

btw.   place the enemy on the object layer and then use createfromobjects is the way to go IMHO.

 i even define some variables for the objects in "tiled"  like "name" "speed" "distance" "type"  etc.   and use them in my code to distinguish my enemies and make my enemies walk in different directions, with different speed for example..

Link to comment
Share on other sites

Never mind. I talked to the creator of Tiled. I was pushing the wrong button.

i posted an issue on github about the GID of tiles but it got closed because of an earlier bug report on it. i have to create a seperate tilemap with tiles from 0,0 to get the correct ID of the tiles.

What 'button' are you pressing?

It would be super helpful to know how to get the GID dynamically in tiled because i cant seem to get it.

Link to comment
Share on other sites

In Tiled:

 

Create a new object layer, and then push the furthest right top button, this will allow you to place tiles as objects:

Screenshot

Here, any solid colored tile is an object that I can reference later in the code.

 

 

Then, the json file you export will look like:

Screenshot

 

Then in code:

// Arguments:// object-layer-name// gid of object to replace// asset key// frame (optional)// exists (optional)// autocull (optional)// group to add to (optional)// CustomClass (optional)// adjustY (optional)this.map.createFromObjects('menu-objects',8,'friendlies',2, true, false, this.bugs);

Documentation: http://docs.phaser.io/Phaser.Tilemap.html#createFromObjects

Link to comment
Share on other sites

well.. that's how you'd get the GID out of the json file.. that's ok but it would be interesting to get the gid of the tile inside of tiled (via the userinterface)

 

@rpiller :  just one example:

game.load.spritesheet('gomba', 'assets/gomba-spritesheet.png', 64, 64);
enemies = game.add.group();map.createFromObjects('objects', 95, 'gomba', 0, true, false, enemies);enemies.forEach(setupEnemies,this);

the enemy "name" is set in tiled...

function setupEnemies(enemy){    if (enemy.name == 'gomba'){        enemy.scale.setTo(0.6,0.6);        enemy.animations.add('walk', [0,1,2,3,4,3,2,1], 10, true);        enemy.animations.play('walk');        enemy.body.setCircle(16);        enemy.body.y += 26        enemy.health=10;         enemy.body.fixedRotation=true;        enemy.body.allowSleep=true;        enemy.body.setCollisionGroup(enemyGroundCG);        enemy.body.collides([playerCG,fireballCG,groundCG,enemyboundsCG]);    }}

and then there is another function called in function update() with forEach() that moves the enemies according to other variables already set up in tiled like "velocity"  for example

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...