[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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.