[Solved]How to move the enemy left and right horizontal loop?

Recommended Posts

Hello everyone, I am developing a platform game like super Mario , I hope the enemy can move left and right horizontal and loop this.

I just use very stupid way to make it.

I use this code is work.

 if (enemy.x<= 450){
            enemy.body.velocity.x = +200;

        }  else if (enemy.x>= 800){
            enemy.body.velocity.x = -200;


if I have more than one enemy, I need to set each of their values.

I try to use  game.add.tween eg game.add.tween(enemy).to({ x: enemy.x+80 }........, It also work!!!!!!! but same problem , I need to set each of their values.

I try to use, but no success.

What are the easy way to set enemy auto move left and right horizontal and loop this?  Thanks you very much.



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.