Bound player to viewport?

Get help using Construct 2

Post » Sun Feb 23, 2014 8:35 am

Is there a way to bound the player to the viewport?

I'm adapting my game to play on several screen resolutions, so bounding the player to the layout won't work because the screen might be larger than the layout and I can't make the player solid because of the game mechanic.
B
3
S
1
Posts: 39
Reputation: 405

Post » Wed Feb 26, 2014 11:31 am

@Fwumpy

Yo,

You could try something like this..
Aslong you are not using Scrollto or camera behaviors on your player and don't want your layout to scroll beyond the viewport...

System> Compare two values
> Player1.Y > 'viewportBottom'
>> set player.y to viewportBottom
--------
System> Compare two values
> Player1.Y < 'viewportTop'
>> set player.y to viewportTop
--------
System> Compare two values
> Player1.X < 'viewportLeft'
>> set player.y to viewportLeft
--------
System> Compare two values
> Player1.X > 'viewportRight'
>> set player.X to viewportRight

** edit, You might want to add +/- pixels to each set X/Y, so that it stays inside the viewport and not halfway out.. ie, if your player is 100 pixels wide then set player.X to "viewportRight+50" etc.

:) hope it helps
B
9
S
2
Posts: 26
Reputation: 586

Post » Thu Feb 27, 2014 7:23 pm

@Ometheu

Awesome! I'll try it tonight. Thank you.
B
3
S
1
Posts: 39
Reputation: 405


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests