Center view on bouncing ball

0 favourites
  • 4 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • I have a large level with the player being a bouncing ball, I would like to center the view on the player as he moves around the level. Now I know about Scroll to object but that follows the movement of the bouncing ball and 'bounces' the level while keeping the player steady, nice effect but not what I'm after. I can keep the player centralized in either the horizontal direction (Set scroll X to player.x) or vertical direction Set scroll Y to player.y) but if I use both it's exactly like using the Scroll to object.


    How do I keep a bouncing sprite centralized while moving around a large level without bouncing the level?

    NOT what I want:

  • Try creating another sprite, giving it the platform movement and making it invisible, then center the camera on it. Then, make the ball always have the same X position as it, while still boucing.. might work.

  • I did try that andreyin but the player can move vertical as well as horizontal around the level. Setting the X position works fine horizontally but not vertically, and of course setting the X and Y will just make it act exactly like Scoll to object. <img src="smileys/smiley24.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could try this:

    every tick:

    ----scroll x to player.x

    player y > scrolly + 100:

    ----scroll y to scrolly + 100*dt

    player y < scrolly - 100:

    ----scroll y to scrolly - 100*dt

    The numbers may need some tweaking, but that makes the screen scroll when the player goes 100 pixels from the center of the screen, so you essentially get a dead zone where no vertical scrolling occurs.

    Another approach that doesn't have a dead zone, but is less jarring than scollto, is to always scroll toward the player at a speed proportional to the distance the player is from the center of the screen.

    every tick:

    ----scroll to position: scrollx+(player.X-scrollx)*2*dt, scrolly+ (player.Y-scrolly)*2*dt

    The numbers can be tweaked to adjust the responsiveness. As it is now it will scroll to exactly where the player is in half a second if the player is not moving.

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