How do I restart the layout if player leaves the viewport?

0 favourites
  • 4 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hi all

    I am trying to make a game wherein the camera follows the player as they jump upward but as they start to fall the camera becomes static and if they are to leave the viewport I want the layout to reset.

    Is there a command or function for detecting when a sprite is outside of the viewport?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ViewportBottom(layer)

    ViewportLeft(layer)

    ViewportRight(layer)

    ViewportTop(layer)

    Return the viewport boundaries in layout co-ordinates of a given layer. Not all layers have the same viewport if they are parallaxed, scaled or rotated separately.

    You can use these expressions to compare the player object's position, and act accordingly.

  • You can also use the inverted "is on screen" condition

  • the way I've done this in the past is I set up "camera points" (dummy sprites) all throughout my layout... and they are all equal distance apart (I use the snap to grid - make grid size the viewport size). Then I have a piece of code that lerp-scrolls to the nearest camera point to the player (Pick nearest). You could build in a slight delay incase the player is right on the edge so it doesn't bounce back and forth too fast - or play with the lerp numbers.

    EDIT:sorry.. I misread that you wanted the camera to scroll when you leave the screen.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)