How do I switch between platform directions?

Get help using Construct 2

Post » Sat Aug 19, 2017 11:01 pm

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
B
15
S
5
Posts: 78
Reputation: 1,173

Post » Sun Aug 20, 2017 9:53 am

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
B
257
S
43
G
15
Posts: 1,992
Reputation: 41,535

Post » Sun Aug 20, 2017 11:20 am

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Aug 20, 2017 5:27 pm

Lordshiva1948 wrote: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!
B
15
S
5
Posts: 78
Reputation: 1,173

Post » Sun Aug 20, 2017 6:04 pm

99Instances2Go wrote: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.

Image
B
15
S
5
Posts: 78
Reputation: 1,173

Post » Sun Aug 20, 2017 6:11 pm

PS: I think I'm not getting the "get it running constantly" part right after all.
B
15
S
5
Posts: 78
Reputation: 1,173

Post » Sun Aug 20, 2017 8:16 pm

: )

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Aug 20, 2017 8:22 pm

99Instances2Go wrote:: )

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)
B
15
S
5
Posts: 78
Reputation: 1,173

Post » Sun Aug 20, 2017 9:08 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Aug 20, 2017 9:21 pm

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.
B
15
S
5
Posts: 78
Reputation: 1,173

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests