Ease in out camera script

Post your own tutorials, guides and demos.

Post » Sat Jun 26, 2010 11:16 pm

Here is a python script for ease in and out camera motion.
[code:2fwplqvv]class myscroll:
def __init__(self):
self.acceleration=100;
self._ax=0; self._ay=0
self._vx=0; self._vy=0

def __call__(self, obj):
myscrollx=(System.ScrollXLeft+System.ScrollXRight)/2
myscrolly=(System.ScrollYTop+System.ScrollYBottom)/2

# x motion
diff=obj.X-myscrollx
if abs(diff)<1:
self._ax=0; self._vx=0
else:
if self._vx**2/(2*self.acceleration) >= abs(diff):
self._ax=-1*cmp(self._vx,0)*self.acceleration
else:
self._ax=cmp(diff,0)*self.acceleration

# y motion
diff=obj.Y-myscrolly
if abs(diff)<1:
self._ay=0; self._vy=0
else:
if self._vy**2/(2*self.acceleration) >= abs(diff):
self._ay=-1*cmp(self._vy,0)*self.acceleration
else:
self._ay=cmp(diff,0)*self.acceleration


self._vx+=self._ax*System.TimeDelta
self._vy+=self._ay*System.TimeDelta
System.ScrollX(myscrollx+self._vx*System.TimeDelta)
System.ScrollY(myscrolly+self._vy*System.TimeDelta)
myscroll=myscroll()[/code:2fwplqvv]
No need to understand how it works, just have that script run at the "start of layout" and call "myscroll(Sprite)" every tick. The only setting is acceleration, which can be changed at any time with the script "myscroll.acceleration=400".

Basically what it does is accelerate the camera to the object and then decelerate so that when the screen arrives at the object the camera speed will be zero.

Example of use: [url:2fwplqvv]http://dl.dropbox.com/u/5426011/examples/camera%20easeinandout.cap[/url:2fwplqvv]
req at least 0.99.84

Feel free to use or enhance.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Sat Jun 26, 2010 11:35 pm

That's a really nice effect, great work! I bet it'd look good combined with a slight pan out when moving and a pan inwards when motionless.

Really cool, thanks for sharing :)
B
15
S
6
G
6
Posts: 103
Reputation: 2,968


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests