jopcode

how to add enemy over a platform ?(tilemap)

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

@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

Share this post


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

Share this post


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

Share this post


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

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.

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

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.