Please Help Me

SO I have a game, and I want it to work like this:
When the screen is tapped, the character goes right, but the next time it is tapped, the character goes left, and that repeats over and over.
How do I do this? Thanks.

Comments

  • illaciaerikillaciaerik Member, PRO Posts: 26

    First off I have to say that I'm not an expert but my first thought when I read your question was to make a integer attribute. +1 every time you tap the screen. Then right when attribute is equal to 1 and left when it's equal to 2. You'll also need reset the count when attribute is equal to 2 and tap is released.

    A theory that might work :) Sorry if my english is sub-par.

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2016

    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

  • bobertoboberto Member Posts: 35

    @illaciaerik said:
    First off I have to say that I'm not an expert but my first thought when I read your question was to make a integer attribute. +1 every time you tap the screen. Then right when attribute is equal to 1 and left when it's equal to 2. You'll also need reset the count when attribute is equal to 2 and tap is released.

    A theory that might work :) Sorry if my english is sub-par.

    Thank you, and no, your english is great :smiley:
    I will try it.

  • illaciaerikillaciaerik Member, PRO Posts: 26

    @Socks said:
    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

    But then the actor never stay still right?

  • bobertoboberto Member Posts: 35

    @Socks said:
    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

    Will the mouse button action work for tapping too?

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2016

    @illaciaerik said:

    @Socks said:
    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

    But then the actor never stay still right?

    Ah! I just re-read the OP, I thought that's what he wanted, you tap to change direction, but I suspect I'm wrong and I think you are right, he only wants it to move when you tap the screen . . . . ! :o :)

    If he wants the actor to stop moving, then he will need to say how long it moves for or under what conditions it stops and so on.

    If he wants the actor to move only while the screen is touched then you just need to change the 'button down' condition in my example to 'touch is pressed'.

  • bobertoboberto Member Posts: 35

    @Socks said:

    @illaciaerik said:

    @Socks said:
    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

    But then the actor never stay still right?

    Ah! I just re-read the OP, I thought that's what he wanted, you tap to change direction, but I suspect I'm wrong and I think you are right, he only wants it to move when you tap the screen . . . . ! :o :)

    If he wants the actor to stop moving, then he will need to say how long it moves for or under what conditions it stops and so on.

    If he wants the actor to move only while the screen is touched then you just need to change the 'button down' condition in my example to 'touch is pressed'.

    Sorry for my unclear question. I want to do what socks thought, my character is always moving forward, but you tap to change direction. How do I do this?

  • bobertoboberto Member Posts: 35

    So I tried it, @socks, but it just goes left very time. How do I make it switch off directions?

  • SocksSocks London, UK.Member Posts: 12,822

    @boberto said:
    So I tried it, @socks, but it just goes left very time. How do I make it switch off directions?

    Can you post a screenshot of your rules . . . .

  • crestwoodgamescrestwoodgames Member Posts: 191

    Maybe something like this would work.

    create a global attribute called direction type integer

    make a rule
    when device touch counter = 1
    change attribute game.direction to mod((game.direction+1),2)

    Inside moving actor
    make a rule
    if game.direction = 0
    change linear velocity X to 200

    otherwise
    change linear velocity X to -200

  • bobertoboberto Member Posts: 35

    @crestwoodgames said:
    Maybe something like this would work.

    create a global attribute called direction type integer

    make a rule
    when device touch counter = 1
    change attribute game.direction to mod((game.direction+1),2)

    Inside moving actor
    make a rule
    if game.direction = 0
    change linear velocity X to 200

    otherwise
    change linear velocity X to -200

    Thank you. I've tried a lot of functions like that, but they all go like this:
    I click once and the actor turns right
    I click again and the actor left
    I click again and nothing happens.

  • bobertoboberto Member Posts: 35

    @socks yes I will

  • bobertoboberto Member Posts: 35

    Ok so here is my full writeup, with updates from some of the comments:
    My character is in a landscape iphone game with no gravity. It has a behavior that says go up at a speed of 150. I have the rotation constrained to my game.direction attribute. How do I get so that when the background is tapped, the game.direction will change each time (for example, first tap changes it to 10, second tap back to 0)
    I hope it makes more sense now. Thanks.

  • SocksSocks London, UK.Member Posts: 12,822

    @boberto said:
    I have the rotation constrained to my game.direction attribute. How do I get so that when the background is tapped, the game.direction will change each time (for example, first tap changes it to 10, second tap back to 0)

    Change x to 10-x

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    When touch is pressed do change attribute game.LeftandRight to (game.LeftandRight+1)%2

    I would suggest putting it in a rule like
    When game.StartGame = 1 or is true (depending on if you used a integer or boolean)
    and when touch is pressed
    Do:
    change attribute game.LeftandRight to (game.LeftandRight+1)%2

    Set it up in how the main actor moves like

    when game.LeftandRight = 0 do Move right
    else:
    move left

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    If you don't have it solved I'll try to make a quick template :)

  • Thunder_ChildThunder_Child Member Posts: 2,343

    Make your actor do this....by default I assume your actor is facing right.....make two Boolean attributes (game level) called left and right.

    Now in your actor make a rule

    "when right is true, move 0* @ speed 100

    Make another

    "When left is true, move 180* @ speed 100

    Now make another rule when touched is pressed and right is true change actor attribute flip horizontal and make left true and right false...then in otherwise make it when touch is pressed and left is true, flip horizontal and make left false and right true.

  • bobertoboberto Member Posts: 35

    @Thunder_Child said:
    Make your actor do this....by default I assume your actor is facing right.....make two Boolean attributes (game level) called left and right.

    Now in your actor make a rule

    "when right is true, move 0* @ speed 100

    Make another

    "When left is true, move 180* @ speed 100

    Now make another rule when touched is pressed and right is true change actor attribute flip horizontal and make left true and right false...then in otherwise make it when touch is pressed and left is true, flip horizontal and make left false and right true.

    Thank you. I actually tried that exact same thing, but I will try it again.

  • Thunder_ChildThunder_Child Member Posts: 2,343

    @jamie_c has a few tutorials and templates I think that are free that explain this in great detail.

  • bobertoboberto Member Posts: 35

    Is there a loop function? Like once everything inside it is done, it runs again?

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2016

    //

  • bobertoboberto Member Posts: 35

    @Socks said:
    //

    what

  • bobertoboberto Member Posts: 35

    @http_gamesalad said:
    If you don't have it solved I'll try to make a quick template :)

    Please do!

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2016

    @boberto said:

    @Socks said:
    //

    what

    I made a post, but decided to remove it as it probably wasn't that helpful.

  • bobertoboberto Member Posts: 35

    @Socks said:

    @boberto said:

    @Socks said:
    //

    what

    I made a post, but decided to remove it as it probably wasn't that helpful.

    OK

  • Thunder_ChildThunder_Child Member Posts: 2,343
    edited January 2016

    @boberto said:

    @Thunder_Child said:
    Make your actor do this....by default I assume your actor is facing right.....make two Boolean attributes (game level) called left and right.

    Now in your actor make a rule

    "when right is true, move 0* @ speed 100

    Make another

    "When left is true, move 180* @ speed 100

    Now make another rule when touched is pressed and right is true change actor attribute flip horizontal and make left true and right false...then in otherwise make it when touch is pressed and left is true, flip horizontal and make left false and right true.

    Thank you. I actually tried that exact same thing, but I will try it again.

    I should add you need to start with right true or left true. One of the has to be true first at start. By default they both would be false. I put that at the top of my logic tree.

  • illaciaerikillaciaerik Member, PRO Posts: 26

    @boberto said:

    @Socks said:

    @illaciaerik said:

    @Socks said:
    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

    But then the actor never stay still right?

    Ah! I just re-read the OP, I thought that's what he wanted, you tap to change direction, but I suspect I'm wrong and I think you are right, he only wants it to move when you tap the screen . . . . ! :o :)

    If he wants the actor to stop moving, then he will need to say how long it moves for or under what conditions it stops and so on.

    If he wants the actor to move only while the screen is touched then you just need to change the 'button down' condition in my example to 'touch is pressed'.

    Sorry for my unclear question. I want to do what socks thought, my character is always moving forward, but you tap to change direction. How do I do this?

    Just divide the screen into to buttons with appropriate attribute. And set a Y velocity to the actor.

    My first game Extreme Highway Challenge works exactly like that.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    This thread is way out of control..lol

  • bobertoboberto Member Posts: 35

    @illaciaerik said:

    @boberto said:

    @Socks said:

    @illaciaerik said:

    @Socks said:
    Make rule for your actor that says . . .

    When mouse button is down
    Change Linear Velocity X to -Linear Velocity X

    Also set an initial Linear Velocity X value in the actor's attributes.

    But then the actor never stay still right?

    Ah! I just re-read the OP, I thought that's what he wanted, you tap to change direction, but I suspect I'm wrong and I think you are right, he only wants it to move when you tap the screen . . . . ! :o :)

    If he wants the actor to stop moving, then he will need to say how long it moves for or under what conditions it stops and so on.

    If he wants the actor to move only while the screen is touched then you just need to change the 'button down' condition in my example to 'touch is pressed'.

    Sorry for my unclear question. I want to do what socks thought, my character is always moving forward, but you tap to change direction. How do I do this?

    Just divide the screen into to buttons with appropriate attribute. And set a Y velocity to the actor.

    My first game Extreme Highway Challenge works exactly like that.

    Okay, I know I can do that.

  • bobertoboberto Member Posts: 35

    Good news! I figured it out!

Sign In or Register to comment.