Changing Direction By Tapping...

Hello everyone! I'm new to this, so forgive me if this isn't the right place for this...

Anywho, I need help. I am trying to make my character change it's direction every time you tap the screen. The character starts the game by automatically moving left, and if you tap the screen it moves right, and if you tap again it goes back to moving left. The character should never stop moving.

Any help is appreciated!

Comments

  • tintrantintran Member Posts: 453
    edited July 2015

    If any of the following condition is happening
    touch is inside
    touch is outside
    do
    change attribute self.motion.linearVelocity.x to -self.motion.linearVelocity.x

  • ArmellineArmelline Member, PRO Posts: 5,407

    Set up a boolean at game level.

    Add the following rule to the player actor:

    When touches.touch 1.active is true
    Change attribute game.Boolean to not(game.Boolean)

    Then, also in the player actor, have another rule:

    When game.Boolean is true
    Your logic to move left
    Otherwise
    Your logic to move right

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @jacobalm - Here's another way to do it.

  • tintrantintran Member Posts: 453

    @Armelline said:
    Set up a boolean at game level.

    Add the following rule to the player actor:

    When touches.touch 1.active is true
    Change attribute game.Boolean to not(game.Boolean)

    Then, also in the player actor, have another rule:

    When game.Boolean is true
    Your logic to move left
    Otherwise
    Your logic to move right

    Interesting. touches.touch1.active? must be a Mac thing.
    I don't see an active attribute under touches.touch1, only x and y.

  • jacobalmjacobalm Member Posts: 2

    @Braydon_SFX said:
    jacobalm - Here's another way to do it.

    Exactly what I was looking to do. Many thanks!

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited July 2015
Sign In or Register to comment.