One touch based movement left or right

Hi, I am new to GameSalad. I want to move a object left or right by one click . When the left mouse click is pressed, the object move to left(100). And when the left mouse click pressed again, object move to right(-100). And it repeat the process left to right, and right to left with same left mouse button pressed every time. If I get some help, I appreciate it !!

Answers

  • RondoRocketRondoRocket Member Posts: 411

    Create an integer attribute (self.click) and then make a rule that says:

    When mouse button pressed

    • change attribute (self.click) to (self.click+1)%2

    Then make another integer attribute (self.speed) and rule that says:

    When self.click = 0

    • change attribute (self.speed) to -100

    Otherwise

    • change attribute (self.speed) to 100

    Put the self.speed attribute into the move behaviors speed setting. Hopefully this gives you something close to what you are looking for.

  • colandercolander Member Posts: 1,610

    @RondoRocket @ishanpatel21@gmail.com sometime ago in a thread @CodeMonkey advised us to use the mod() function not %. Instead of (self.click+1)%2 use mod(self.click+1,2). I can't remember why maybe he can remind us if he see this.

  • Thanks @RondoRocket @colander. it works.

Sign In or Register to comment.