Touch to change rotation direction doesn't work

hamzawesomehamzawesome Member, PRO Posts: 30
edited March 2016 in Working with GS (Mac)

I'm trying to make it so that whenever the screen is touched while the actor is rotating clockwise, the actor will start rotating counter-clockwise and vice-versa. Tapping the screen once while the actor is rotating should simply cause it to change direction, not when the screen is held but just when it is tapped and released. I've created an integer called "counter" wherein every time the screen is touched, the value of counter will change from 1 to -1, or from -1 to 1. I've also created a rule that says whenever counter < 0, the actor rotates clockwise and whenever counter > 0, the actor rotates counter-clockwise. At the start of the game, the value of counter is 1, so it starts off rotating counter-clockwise.

The problem is, when I touch the screen, the actor won't change to clockwise. In other words, the value of 'counter' won't change the way it's supposed to. Here's the rule I've made to change the value of counter to -1 when the screen is touched while the actor rotates counter-clockwise (counter > 0):

Also here's the rule I've created to change the value of 'counter' to 1 when the screen is touched while the actor is rotating clockwise (counter < 0), thus changing the direction to counter-clockwise:

For some reason it doesn't work; when the screen it touched, the direction of the actor's rotation doesn't change. It just continues rotating the way it already was and doesn't change. I assume this is because the value of "counter" isn't changing the way it's supposed to. Can anyone help me figure out why? I really appreciate it. Please let me know if anything I've described doesn't make sense.

Comments

  • IceboxIcebox Member Posts: 1,485
    edited March 2016

    @hamzawesome Create an integer game attribute , call it Switch , In your touch actor create this rule

    When actor recieves event touch is pressed

    Change attribute Game.Switch to mod((Game.Switch+1),2)

    ( this will change the game switch attribute to either 1 or 0 , when you press it)

    Now in your rotate actor just put one rule

    Rule
    if game.switch = 0
    Rotate clockwise
    otherwise
    rotate counterclock

    Hope this helps goodluck

  • hamzawesomehamzawesome Member, PRO Posts: 30

    @Icebox said:
    @hamzawesome Create an integer game attribute , call it Switch , In your touch actor create this rule

    When actor recieves event touch is pressed

    Change attribute Game.Switch to mod((Game.Switch+1),2)

    ( this will change the game switch attribute to either 1 or 0 , when you press it)

    Now in your rotate actor just put one rule

    Rule
    if game.switch = 0
    Rotate clockwise
    otherwise
    rotate counterclock

    Hope this helps goodluck

    Thank you so much, that worked!

Sign In or Register to comment.