How do I switch between platform directions?

0 favourites
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • Hey guys!

    Me again! haha.

    Well, I have this idea for another game. My first game was an infinite runner, and I like the idea of simple controls. However, the infinite runner was a bit too simple, so I want to make a single-screen platformer.

    However, I want the running to be automatic. All I want the player to be able to do is jump and (crucially) change the direction in which the player sprite is running (left or right).

    I can start the layout with the player sprite running left, and have a button that switches that to right, no problem. However, I need to use the same button to make it go left again.

    Basically, I need a button that alternates between running directions (left and right). I think I need something like "if sprite is running left, then go right. if sprite is running right, go left" or some such thing but I can't seem to figure out how to do it.

    Any ideas, guys? No capx as this is very barebones and that's about as far as I got. If I can't get the thing to run so no point, right? It should be just a single event, though, if I'm right?

    Let me know, please!

    And thank you for your support through my game creating journey <3

  • you could do it like so

    on mouse left BUTTON click on sprite_button the player move Right

    on mouse right BUTTON click on sprite_button the player move Left

  • Usually, the player does not move on the X-axis in an infinite runner. Everything else is moving.

    Give the button a instance Boolean 'Switch'

    On button clicked

    ____Sub .. Button > Is Boolean instance variable set ... 'Switch'

    __________action .. Button > Set Boolean ... 'Switch' to false

    __________All the other actions you need to switch direction

    ____Else

    __________action .. Button > Set Boolean ... 'Switch' to true

    __________All the other actions you need to switch direction

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • you could do it like so

    on mouse left BUTTON click on sprite_button the player move Right

    on mouse right BUTTON click on sprite_button the player move Left

    Hi!! Thanks for the idea! Sadly, I'm going to make this a mobile title so I need a single button for a touch interface. Thanks for the idea, though!

  • Usually, the player does not move on the X-axis in an infinite runner. Everything else is moving.

    Give the button a instance Boolean 'Switch'

    On button clicked

    ____Sub .. Button > Is Boolean instance variable set ... 'Switch'

    __________action .. Button > Set Boolean ... 'Switch' to false

    __________All the other actions you need to switch direction

    ____Else

    __________action .. Button > Set Boolean ... 'Switch' to true

    __________All the other actions you need to switch direction

    Hey 99Instances2Go

    Thanks for helping me again! You've always been great to me. I really appreciate it. As per usual, I'm over my head. Here's what I've got, and it doesn't work at all.

  • PS: I think I'm not getting the "get it running constantly" part right after all.

  • : )

    On button clicked

    ____Sub .. Button > Is Boolean instance variable set ... 'Switch'

    __________action .. Button > Set Boolean ... 'Switch' to false

    __________All the other actions you need to switch direction

    ____Else

    __________action .. Button > Set Boolean ... 'Switch' to true

    __________All the other actions you need to switch direction

  • : )

    On button clicked

    ____Sub .. Button > Is Boolean instance variable set ... 'Switch'

    __________action .. Button > Set Boolean ... 'Switch' to false

    __________All the other actions you need to switch direction

    ____Else

    __________action .. Button > Set Boolean ... 'Switch' to true

    __________All the other actions you need to switch direction

    Haha what a dummy I am.

    That changes direction with the code I have, but only one step. The guy doesn't move more than one step. I wonder if I'm missing something to get it to move in that direction until the button is pressed again?

    Any ideas? 99Instances2Go ? Anybody? Bueller? (sorry, couldn't resist)

  • Well the moving things in that case should be a separate event to allow it to run every tick.

    On button clicked

    ____Sub .. Button > Is Boolean instance variable set ... 'Switch'

    __________action .. Button > Set Boolean ... 'Switch' to false

    ____Else

    __________action .. Button > Set Boolean ... 'Switch' to true

    Thing is on the floor

    ___ Sub Is Boolean instance variable set ... 'Switch'

    ______________Simulate left.

    ___Else

    ______________Simulate right.

    But, i dont understand how you make that into an infinite runner.

    An infinite runner stays on its position on screen, everything else is moving. No ?

    That is the reason why i had it in 1 event.

  • That's awesome! Thank you 99Instances2Go!

    I think I rushed through my OP. I'm not making an infinite runner this time, but a semi-automated single screen platformer. A bit like 10 Second Ninja X, but with automated controls. Basically you can only decide the direction of running and where to jump, and you'll have to avoid obstacles.

  • I thought I replied to this thread already!

    you can do it using Is Mirror condition:

    On button touch

    • Is mirrored: Set Not Mirrored, do other stuff

    Else: Set Mirrored, do other stuff

    And you good to go

  • Ahhh, wel now i am up to date eh.

  • I thought I replied to this thread already!

    you can do it using Is Mirror condition:

    On button touch

    - Is mirrored: Set Not Mirrored, do other stuff

    Else: Set Mirrored, do other stuff

    And you good to go

    Thank you! I actually ended up using 99Instances2Go 's solution to great success. I'm exporting to Cordova/Cocoon right now to see if I didn't eff up code.

    Thanks for chiming in! I think it may be a simpler solution, the one you propose, but I already have this in place, haha.

  • Ahhh, wel now i am up to date eh.

    Haha apologies for the confusion, and thanks very much for the help!

  • marcoscodas for that you could do it like so

    is touching button then move right else

    not touching button move left

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)