Wednesday, April 10, 2013

Game Flair

I know I'm deviating a bit from that last couple posts about designing a simple game with pygame libraries. But I stumbled upon a video that got me thinking about some of the little things you can add to a game to make them more interesting. If you're interested this is the video I'm referring to.

One really simple idea that they had was to use tweening or easing. Instead of just placing a new sprite or game object on the screen, we have it drop into place or instead of game objects just vanishing, you can use this to slowly scale them out of existence.

The way they did this was using something like:

x += (target-x) *.1

This is probably the most simple approach to tweening. Basically we give the sprite or rectangle a target and a starting point. Then we move the x by 10 percent until it gets to the destination or target. Simple right?

And it provides a really nice effect to the game for very little cost.

That's the easiest implementation of tweening/easing. If you want to get fancier you have to do a bit more math.

Here's a basic function to get you started

def linearTween(time, startPoint, change, endPoint):
  return change * time / endPoint + startPoint

time is the current time in frames, steps, whatever counter you want to use. As long as it is a percentage of the endPoint

startPoint is the value where we begin

change is the difference between the beginning and destination values

endPoint is the end time or frame or whatever for your tween.

Basically it's the same thing as x += (target-x) *.1 since you have a start, a target, diff, and percentage of change. However in this way we have a number of variables we can use in a bunch of different ways.

Check out this site: http://www.timotheegroleau.com/

He has a generator for easing functions that you can use for all sorts of fun stuff. In fact, Tim Groleau has a collection of material on the subject if you're interested.

-Newt

No comments:

Post a Comment