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 />

Computationally this uses much less processing power, for no loss of accuracy. Always look<br />

out for times when you can lower the hit on the processor because your games will play more<br />

smoothly.<br />

It doesn’t seem very logical <strong>to</strong> me!<br />

We’ve looked at how we can use the ‘if ’ statement <strong>to</strong> select which code <strong>to</strong> run. So far we have<br />

used a single condition. But we can combine conditions using either an ‘And’ operation or an<br />

‘Or’ operation. <strong>Flash</strong> uses the symbol ‘&&’ <strong>to</strong> represent And, and the symbol ‘||’ <strong>to</strong> represent Or.<br />

So how do we use these <strong>to</strong> combine conditions? The ‘And’ option means that all the conditions<br />

must be true for the combined condition <strong>to</strong> evaluate <strong>to</strong> true. The ‘Or’ option just requires a<br />

single condition <strong>to</strong> evaluate <strong>to</strong> true for the combined result <strong>to</strong> evaluate <strong>to</strong> true. Truth tables are<br />

often used <strong>to</strong> show the results of combinations; Table 8.2 gives the truth tables for both ‘And’<br />

and ‘Or’.<br />

Let’s look at how we can use these options <strong>to</strong> improve our<br />

conditional statements. Suppose we want <strong>to</strong> run a section of<br />

code if our character is inside a rectangle on screen. We will<br />

Table 8.2 And and Or truth<br />

define the rectangle using the upper left corner and the lower<br />

tables �<br />

��� �<br />

And<br />

��<br />

true false<br />

right corner. To be within the region the character’s _x pos-<br />

true<br />

��<br />

��<br />

�<br />

ition must be greater than the value for left of the rectangle<br />

true false<br />

false ��<br />

� false false<br />

and also less than the value for right, in addition the character’s<br />

�<br />

��<br />

Or ��<br />

true false<br />

_y position must be greater than the <strong>to</strong>p line of the rectangle<br />

��<br />

true ��<br />

��<br />

� true true<br />

but less than the bot<strong>to</strong>m line. So how do we put this in<strong>to</strong><br />

false �<br />

�<br />

� true false<br />

code? Let’s consider the rectangle (100, 200, 300, 400). Here<br />

the left side is at 100, the <strong>to</strong>p is at 200, the right is at 300<br />

and the bot<strong>to</strong>m is at 400. If we have a movie clip called clip then the code we would use<br />

would be:<br />

if (clip._x>100 && clip._y>200 && clip._x<strong>to</strong>p && x

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

Saved successfully!

Ooh no, something went wrong!