Jump to content

how to add enemy over a platform ?(tilemap)


jopcode
 Share

Recommended Posts

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

 

Regards,

ITpaolo

 

Link to comment
Share on other sites

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.

 

Captura.PNG

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

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

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);
        }

 

61c276bcc5a1dbb1f0302b37d828750f.gif

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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