0 Favourites

Bound player to viewport?

  • 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Fwumpy


    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

  • Ometheu

    Awesome! I'll try it tonight. Thank you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
[plugin] Youtube player
175 20,546
rexrainbow's avatar
Unread hot topic
44 2,230
Prevter's avatar
Unread hot topic
43 2,266
Zebbi's avatar