Bound player to viewport?

0 favourites
  • 3 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • 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.

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)