Center view on bouncing ball

Get help using Construct 2

Post » Thu Oct 20, 2011 8:02 pm

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.

So...

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

NOT what I want: http://dl.dropbox.com/u/2485349/Bounder/index.html
B
72
S
25
G
9
Posts: 382
Reputation: 10,649

Post » Mon Oct 24, 2011 6:05 pm

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.

B
106
S
35
G
37
Posts: 798
Reputation: 25,215

Post » Mon Oct 24, 2011 11:04 pm

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.
B
72
S
25
G
9
Posts: 382
Reputation: 10,649

Post » Tue Oct 25, 2011 5:02 am

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. R0J0hound2011-10-25 05:04:31
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755


Return to How do I....?

Who is online

Users browsing this forum: Televangelist and 22 guests