Jump to content

When hit the walls turn direction


Renanfgs
 Share

Recommended Posts

Hi guys,

I'm a new student and I knew Phaser since 5 days and it's fantastic. So I'm a beginner.

I'm trying to create one simple platform game, I have one issue but I don't know how to solve it. I'll appreciate your help.

I need that when the animation hit the wall he changes the direction, right or left and keep running.

Here's the part of the code that I think is necessary for analyses:

   //  Collide the player with the walls
    var hitWalls = game.physics.arcade.collide(player, walls);
    game.physics.arcade.collide(stars, walls)

    //My animation starts running to right and I want it
    player.body.velocity.x = 200;
    player.animations.play('right',15,true);
   
    if (hitWalls)  ????
       { 
       //Here I tried: player.body.velocity.x = -150; but the animation is crazy now
       }

Thanks and have a good day!

 

 

 

 

Link to comment
Share on other sites

  • 3 weeks later...

I know the topic is about 2 weeks old but maybe still relevant (and sorry for digging up that other post ^^).

 

If you only move on the x-axis, you can simply invert the velocity for by using this:

player.body.velocity.x = player.body.velocity.x * -1;

 

To flip the sprite animation when moving in the other direction, you can either have an individual animation frame for this or invert the sprite by setting the scale for its x-axis to -1.

// Set Anchor to the center of your sprite

yourSprite.anchor.setTo(.5,.5);

// Invert scale.x to flip left/right

yourSprite.scale.x *= -1;

 

This however also inverts the width and might cause other problems (you might want to use absolute values for width and height then).

See this post for examples and more insight into sprite flipping:

 

Link to comment
Share on other sites

I need your help. I'm a student of The University of Illinois at Chicago. I got the task to create a presentation "Interrelation of Higher Mathematics and Informatics".
I need to show the students that the modern stage of science is characterized by the interconnection of mathematics, physics, informatics and other branches of knowledge. With the search for the text for my report, there were no problems, I turned to the specialists of the Essayshark.com company. But I have a problem with in finding the right images for my presentation. Do you know some good resources? Thank you!

Link to comment
Share on other sites

On 15/06/2017 at 11:40 AM, TammySmith said:

I need your help. I'm a student of The University of Illinois at Chicago. I got the task to create a presentation "Interrelation of Higher Mathematics and Informatics".
I need to show the students that the modern stage of science is characterized by the interconnection of mathematics, physics, informatics and other branches of knowledge. With the search for the text for my report, there were no problems, I turned to the specialists of the Essayshark.com company. But I have a problem with in finding the right images for my presentation. Do you know some good resources? Thank you!

is this some really weird bot?

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

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

  • Recently Browsing   0 members

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