Jump to content
  • Advertisement
Sign in to follow this  
Whorse

2d Game Edge Bouncing Effects

This topic is 2304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!