How do I switch from player 1 to player 2

Just started using Construct 2? Post your questions here

Post » Sun Nov 20, 2016 10:20 am

Hi,

Recently downloaded the demo of constructor and love it, I've learned a lot but so far I can't switch from on player to another.
I've looked at all the youtube videos and tutorials but they all add in extra things which I don't need.
Could any one tell me how to have two sprites on screen (player 1 and player 2) and when I click another sprite (change player) the next player is then active. When I press change player again it goes back to player 1.

Any help would be really great.
Mark
B
10
S
3
Posts: 55
Reputation: 802

Post » Sun Nov 20, 2016 11:00 am

You enable/disable the platform or 8-direction behaviour (however they move). Assuming they are two different objects, have an instance variable on the change player button that goes between 1 and 2 when clicked or something similar. When the button shows 1, then enable movement on player 1, disable on player 2, when the button shows 2, then disable movement on player 1, enable on player 2.
B
47
S
17
G
81
Posts: 2,226
Reputation: 48,099

Post » Sun Nov 20, 2016 5:50 pm

Thank you so much for your reply, I understand what you say and it makes sense.
But :( don't hate me. :(

I've added an instance variable on the changer player button, I set number to 1

The picture below works and stop both of them moving (I've not added anything to stop them both moving at the start)
but when I click change player again, nothing happens.
I know I've done something wrong, sorry to be a pain.

Image
B
10
S
3
Posts: 55
Reputation: 802

Post » Sun Nov 20, 2016 6:17 pm

We don't hate people that need help with C2 lol. You need a condition that blocks the other one out. All actions run at once when it is true and from top to bottom in C2. You need to put in a condition on the left, something like on clicked if changeplayer is 0, set changeplayer to 1. And on event 3 you need if changeplayer is 1 set changeplayer to 0. However, because they run top to bottom in C2, you're going to find that it looks like nothing is happening because event 1 is true then event 3 is true. Usually for this i add a wait of 0.1secs on the actions on the right hand side.
B
47
S
17
G
81
Posts: 2,226
Reputation: 48,099

Post » Sun Nov 20, 2016 7:04 pm

Thank you once again, believe it or not I really do try to learn things myself without having to ask people.

I think I've done what you suggested and only the first player moves, when I click change player, the first still moves.

Thank you so much.

Image
B
10
S
3
Posts: 55
Reputation: 802

Post » Sun Nov 20, 2016 7:31 pm

You could also use a global variable that switches between Players depending on what it is set on
B
4
Posts: 9
Reputation: 218

Post » Mon Nov 21, 2016 8:24 am

Hi,

Thank you, I got it working in the end, I needed to put every tick.

I'll paste it below in case someone else finds this post one day. Thank you once again for your help.

Image
B
10
S
3
Posts: 55
Reputation: 802

Post » Mon Nov 28, 2016 5:07 am

I think a more efficient way to do that would be to give both players the "scroll to" behavior and turn it on and off like you do with 8Direction. The advantage there is that you can add "Trigger once" to the conditions for Changeplayer=0 or Changeplayer=1, and the event won't have to run every tick. The difference is meaningless for a small game, but it can become important to avoid triggering events more often than necessary if performance becomes an issue.
Eh, Steve!
B
115
S
54
G
13
Posts: 113
Reputation: 16,151


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest