Power User: Skyboy’s Key Class: Specialized Functions

Posted: November 21, 2010 in Uncategorized

There are some lesser known functions in the Key class. I plan on going thru them one by one until it is clear of what and how they work. The first we will examine is anyDown(). This function is for checking whether -you guessed it- any keys are down! YAY!!! The way this works is as follows:

It analyzes  the sector in which the keyboard is in your webcams camera and then looks to see if the pressure traces on the key is visible. JK, it is much simpler than that. Let’s look at the code :

<blockquote>public static function anyDown(code1:int, ...codes):Boolean {

if (code1 >= 0 && code1 <= 1048575) {
if (Keys[code1]) return true ;

}
for each (var code:int in codes) {
if (code >= 0 && code <= 1048575) {
if (Keys[codeKey]) return true; *

}
}

Let’s go line by line:

if (code1 >= 0 && code1 <= 1048575) {

(This checks if  code1 is bigger or equal to 0 and smaller or equal to 1048575. Please note that code1 WILL be within that range if any keys are pressed.)

if (Keys[code1]) return true ;}

This checks if (Keys[code1]) is down. If it is, anyDown will be true;

for each (var code:int in codes) {
if (code >= 0 && code <= 1048575) {
if (Keys[codeKey])) return true; *

This little chunk checks if any keys are down. If they are, anyDown will be true

Here is the usage:

if ( Key.anyDown(Key.A, Key.S))
{
DO SOMETHING
}

I hope this has helped you to understand the way anyDown works.
Write in the comments below any Comments/Suggestions!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s