2d Game Edge Bouncing Effects

Started by
1 comment, last by Whorse 12 years ago
I've recently been experimenting and attempting to recreate an iOS UI sort of edge bouncing effect in my game so that if you scroll past a level's boundaries, the camera slowly bounces back to the boundary.

At the moment I've implemented some of Robert Penner's tweening calculations ported from ActionScript, however I'm unsure whether this is the correct approach due to the fact that it doesn't take into account our camera's velocity. At the moment it looks something like this:


easeInOut(currentTime, startValue, endValue, duration);


The actual implementations are available here: http://www.jesusgollonet.com/blog/2007/09/24/penner-easing-cpp/

I've come to the conclusion that this is a sort of grey area as I haven't been able to find much information on it, either that or I'm not familiar with the correct name for the sort of calculation I'm attempting to describe. If anyone has any advice, or solutions that include velocity in their games or UI's, I'd be very interested to hear it!
Advertisement
A simple solution would be to move the camera a percentage of the distance back to the boundary each step; that is, if the camera is off the level on the left, each step add a*(leftBoundary - cameraPosition) to cameraPosition, where a is a tunable constant between 0 and 1. Steps happen very quickly, so a will probably be a lot closer to 0 than to 1. If your timesteps are of variable length, you'll need to adjust a each timestep to get a consistent appearance. I don't know your mathematical background; if you need help with that please say.

The bounce-back speed is calculated each step from the position, so if the user scrolls while the camera is already sliding back, the speed changes automatically. If I'm understanding your camera velocity issue correctly, then, it shouldn't be a problem for this method.
Thanks for the insight, I had a suspicion that the most managable way to achieve this was on a frame by frame basis, I have a fixed timestep already, so that much is covered. I'm going to implement your solution on Monday after which I'll share my results on here! Thanks again!

This topic is closed to new replies.

Advertisement