Placing Enemies on a tilemap

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..

Share this post

Link to post
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.

Share this post

Link to post
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:


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:



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)'menu-objects',8,'friendlies',2, true, false, this.bugs);


Share this post

Link to post
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 =;map.createFromObjects('objects', 95, 'gomba', 0, true, false, enemies);enemies.forEach(setupEnemies,this);

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

function setupEnemies(enemy){    if ( == 'gomba'){        enemy.scale.setTo(0.6,0.6);        enemy.animations.add('walk', [0,1,2,3,4,3,2,1], 10, true);'walk');        enemy.body.setCircle(16);        enemy.body.y += 26;         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




Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.