codevinsky Posted April 17, 2014 Share Posted April 17, 2014 What's the best way to go about this? This isn't a "show me the code" question, but more of a theory question. Link to comment Share on other sites More sharing options...
Fishrock123 Posted April 17, 2014 Share Posted April 17, 2014 This question is very general and unspecific.The answer(s) could be any number of things depending on the type of game and other setup >_< Link to comment Share on other sites More sharing options...
drhayes Posted April 17, 2014 Share Posted April 17, 2014 My plan is to use an objectlayer in Tiled for enemies, then use the http://docs.phaser.io/Phaser.Tilemap.html#createFromObjects call with a CustomClass to create the sprites. Are your needs more complicated than that? Link to comment Share on other sites More sharing options...
codevinsky Posted April 17, 2014 Author Share Posted April 17, 2014 drhayes: no. that's what i'm attempting to do right now. However, I'm afraid that my knowledge of tiled lacks somehting to be desired. I've created objects on an object layer, but Tiled isn't exporting a gid for those objects. Link to comment Share on other sites More sharing options...
codevinsky Posted April 17, 2014 Author Share Posted April 17, 2014 Never mind. I talked to the creator of Tiled. I was pushing the wrong button. Link to comment Share on other sites More sharing options...
valueerror Posted April 18, 2014 Share Posted April 18, 2014 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 More sharing options...
rpiller Posted April 18, 2014 Share Posted April 18, 2014 @valueerror, enemies generally have spritesheets for animations. How do you handle that in Tiled and createFromObjects()? Link to comment Share on other sites More sharing options...
Heppell08 Posted April 18, 2014 Share Posted April 18, 2014 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 More sharing options...
codevinsky Posted April 18, 2014 Author Share Posted April 18, 2014 In Tiled: Create a new object layer, and then push the furthest right top button, this will allow you to place tiles as objects:ScreenshotHere, 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 drhayes 1 Link to comment Share on other sites More sharing options...
valueerror Posted April 18, 2014 Share Posted April 18, 2014 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 rpiller and kctang 2 Link to comment Share on other sites More sharing options...
Recommended Posts