Changing the player controller of a behaviour during game

For questions about using Classic.

Post » Mon Sep 13, 2010 6:24 pm

Hi all
Here's my problem.

I have an object using the basic plateform behaviour in construct.
By default it's Player 1 controlling it.
I want it to be controlled by Player 2 when needed.
But i don't find any ways to change this.

I've controls for player 1 and player 2 set. But i cannot switch the "owner" to player 2
(i've thought about put 2 controller one for player 1 , one for player 2, but i will need to duplicate a lot of things to do this, its not very elegant)

If you have a elegant solution to handle this kind of thing (2D fight game, you chose your character but mirror match are forbidden)
I ll be glad to here it :)

Thanks all
Posts: 2
Reputation: 829

Post » Mon Sep 13, 2010 9:23 pm

The simplest way to do this would be to simply give your player sprite two platform behaviours, set them up for player 1 and 2, and a private variable to keep track of which player is allowed control, then change the variable whenever you need.

If the variable is "1" you deactivate platform behaviour for player 2 and vice versa.

Here's a cap, should be fairly self-explanatory.
Posts: 524
Reputation: 9,896

Post » Tue Sep 14, 2010 11:13 am

Thanks for your reply inkbot.

I know this could work. But i wish i could do it another way.
Because with 2 plateform behaviour i need to duplicate all the
is_jumping etc ... events
Because the test is done only for first behaviour

i've already test it. it works but with second player no animation is played.

Thanks anyway it seems there is no easy / lazy solution :p

PS : couldn't open your cap, dont know why, i've the latest version of construct
Posts: 2
Reputation: 829

Post » Tue Sep 14, 2010 6:02 pm

Here's another way to do it with only one platform behavior. You can override controls with the "set control state" action of the MouseKeyboard object.

+ System: Always (every tick)
-> MouseKeyboard: Set control "Move Left" of player 1 to 0

+ MouseKeyboard: Key A is down
-> MouseKeyboard: Set control "Move Left" of player 1 to 1

Here's an example cap.
made with 0.99.94
Posts: 5,555
Reputation: 85,323

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest