02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

Figure B.5 A section of the cosine curve<br />

var n, dt = time/duration;<br />

n = Math.cos(Math.PI/2 * dt + Math.PI) + 1;<br />

_x = offset.x * n + start.x;<br />

_y = offset.y * n + start.y;<br />

For an ease out we will use the curve between 3PI/2 and 2PI; this section of the curve already<br />

gives values between 0 and 1 so we do not need <strong>to</strong> scale or shift the values.<br />

var n, dt = time/duration;<br />

n = Math.cos((Math.PI * (dt + 3))/2);<br />

_x = offset.x * n + start.x;<br />

_y = offset.y * n + start.y;<br />

The final option is <strong>to</strong> use the full curve <strong>to</strong> give both an ease in and out. For this we must use the<br />

full curve between PI and 2PI, the returned values will vary between plus and minus 1 so we must<br />

add 1 then divide by 2 <strong>to</strong> give returned values between 0 and 1.<br />

var n, dt = time/duration;<br />

n = (Math.cos(Math.PI * dt + Math.PI) + 1)/2;<br />

_x = offset.x * n + start.x;<br />

_y = offset.y * n + start.y;<br />

Exponential tweening<br />

Another curve that can give a very fast ramp is the curve y = 2 x . Any number raised <strong>to</strong> the<br />

power zero is equal <strong>to</strong> 1. As you know, the value of dt ranges between 0 and 1, but we<br />

400

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!