jopcode Posted January 16, 2017 Share Posted January 16, 2017 Hi guys, i want to add an enemy over a platform and this enemy can move in the limit of the selected platform, i'm using tilemap created with tiled, but i do not have idea how do it, any idea? Link to comment Share on other sites More sharing options...
ITpaolo Posted January 16, 2017 Share Posted January 16, 2017 If you want to add an enemy, you need to add a Tileset in Tiled and Place it as Object. Then you need to save the file as .json and in the play.js you need to compile it in the Game. e. g. : map.createFromObjects('obj1', 2, 'floor', 0, true, false, Floor); 'obj1' is the name of the Object in Tiled '2' is the gid ID in the .json file 'floor' is the TilesetImage you added in the play.js like: 'Floor' is the variable you defined in the index.html map.addTilesetImage('floor', 'water', 'frog'); Correct me if I'm wrong. How you do the enemy only move in the limited Platform, I dont know either. Hope someone can answer. Regards, ITpaolo Link to comment Share on other sites More sharing options...
jopcode Posted January 16, 2017 Author Share Posted January 16, 2017 @ITpaoloBut, my map has been already created, tileset, json etc has been created and placed, i want place a enemy over a platform already created, and this enemy only can moved(right to left, left to right) over this platform. Link to comment Share on other sites More sharing options...
ITpaolo Posted January 16, 2017 Share Posted January 16, 2017 4 minutes ago, jopcode said: @ITpaoloBut, my map has been already created, tileset, json etc has been created and placed, i want place a enemy over a platform already created, and this enemy only can moved(right to left, left to right) over this platform. Is the enemy a tile layer? If yes, I dont know, I do my enemys with the Object function and place it. You can do this for you enemys: if (jesus.body.x>1000 || jesus.body.x<0) { // bewegung umkehren jesus.body.velocity.x *= -1; } So if he arive x>1000 he will swap his velocity to the other direction. I did this so with my first game with Phaser. For the Clouds in my 2D Game, I did: if (cloud1.body.x>1000 || cloud1.body.x<0) { // bewegung umkehren cloud1.body.velocity.x *= -1; } if (cloud2.body.x>1000 || cloud2.body.x<0) { // bewegung umkehren cloud2.body.velocity.x *= -1; } Regards, ITpaolo Link to comment Share on other sites More sharing options...
jopcode Posted January 16, 2017 Author Share Posted January 16, 2017 @ITpaolo this enemies already can move, but I want place this enemies over the platforms and only can moved inside the platforms Link to comment Share on other sites More sharing options...
ITpaolo Posted January 16, 2017 Share Posted January 16, 2017 Just now, jopcode said: @ITpaolo this enemies already can move, but I want place this enemies over the platforms and only can moved inside the platforms Hmm, so sorry to say but I dont know how this works. I only can say you can test with my Code. Sorry, that I can't help you with this :-/ Regards, ITpaolo Link to comment Share on other sites More sharing options...
jopcode Posted January 16, 2017 Author Share Posted January 16, 2017 @ITpaolothanks anyway ITpaolo 1 Link to comment Share on other sites More sharing options...
jopcode Posted January 17, 2017 Author Share Posted January 17, 2017 Someone can help me please? Link to comment Share on other sites More sharing options...
jopcode Posted January 18, 2017 Author Share Posted January 18, 2017 I got it, first create an Object on Tiled for each Platform that contains the Width, Height, X and Y, and with these parameters I could complete my objective, I leave the code used in case is useful for someone (Sorry for my bad english) this.PlatformsLayer = this.map.objects.PlatformsLayer; for (var i = 0; i < this.PlatformsLayer.length; i++) { this.enemyGround.create(this.PlatformsLayer[i].x, this.PlatformsLayer[i].y - 32, 'tiles', 66); this.xMove = (this.PlatformsLayer[i].x + this.PlatformsLayer[i].width) - 32; this.game.add.tween(this.enemyGround.children[i]).to({ x: this.xMove }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true); } Link to comment Share on other sites More sharing options...
Recommended Posts