How do I restrict player boundaries to visible area

Get help using Construct 2

Post » Thu Feb 25, 2016 1:29 pm

Hi all,
I've been toying with the idea of making a streets of rage sort of clone of sorts. What sprang to mind was the progression through the stages. First off you walk forward then at certain points hit a 'choke point' in which you need to defeat a bunch of enemies before moving on.

I wondered how this might be achieved with something like C2. So my thinking was that you restrict the player to the visible area (so they can't go past those boundaries), until of course they've met certain conditions, then you re-enable it again.

So far I've just thought of dropping some solid objects just out of view, but that seems a bit messy. Or doing some sort of x coordinate comparison, if they're heading off-screen then prevent movement in that direction, etc.

Is there a simpler solution, or do you think the coord check might do the job smoothly enough?

Cheers!
B
5
Posts: 22
Reputation: 283

Post » Thu Feb 25, 2016 2:02 pm

Just some thoughts
put invisible sprites in the way of obj_player as trigger points when the camera has to freeze
when camera is in freeze mode obj_player will be bound to screen
if obj_enemies are destroyed reactivate camera

And yes, you could do
if camera is in freeze - create solid object left and right of the screen.
Or if player ist at Y<=0 then move player +Y 5
or ...

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Thu Feb 25, 2016 2:51 pm

Thanks for your reply! That's a good point, could work pretty well actually. It sounds more friendly rather than having to mess around with velocity and whatnot.

Currently player behaviour 'scrollTo' is active. Disabling this would freeze the screen tracking, is that what you're referring to?
B
5
Posts: 22
Reputation: 283

Post » Thu Feb 25, 2016 3:02 pm

when you hit the trigger point you can set the camera to any point you like
still need to give your obj_player a bound to layout behaviour or invisible objects outside screenwidh

To get total freedom
create obj_camera with a scroll to behaviour. Pin it to obj_ player - or do whatever you like.

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Thu Feb 25, 2016 3:13 pm

Ah! I see what you mean. Thanks very much, I'll give it a shot. :)
B
5
Posts: 22
Reputation: 283

Post » Thu Feb 25, 2016 4:07 pm

Just to confirm that it was pretty much just a case of sticking a block on the left of the camera using ViewPortLeft("CameraLayer"), and ViewPortRight("CameraLayer") to fix them in place. When the camera stops scrolling, the player cannot leave the bounds.

Also, enemies can freely pass through, so if you wanted to spawn stuff off-screen, you don't need to worry about that bit either. :)

It's made even nicer by the fact you can just turn the camera 'scrollTo' back on again whenever you wish.

Thanks again fm for your help!
B
5
Posts: 22
Reputation: 283


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, MadSpy and 7 guests