Code

The readme.txt file in the download ZIP (linked to at the left) provides full instructions on installing and using the code.  Example document classes are provided.  Below is the operative code to get Penguin running so that you get the idea.

Assuming that you import the Penguin class as detailed in the ZIP file.

private var myPenguin:Penguin;

public function TiltBall() {

 // create a Penguin object to track tilt and translation data
 // this data comes from an XML file of tiltML format
 // pass the file path to this data file into the Penguin object
 // The Penguin Tilt Emulator tells you the path
 // if you get data from another program put that path here

 var myFile:String = "file:///C:/somepath/tilt.xml";
 myPenguin = new Penguin(myFile);
 myPenguin.addEventListener(Event.CHANGE, doTilt);

 addEventListener(Event.ENTER_FRAME, doAnimation);

}

private function doTilt(e:Event) {        

 // retrieve the roll and pitch properties
 // adjust move variables used in the animate function

 moveX = e.target.roll;
 moveY = e.target.pitch;    

}

private function doAnimation(e:Event) {    

 // use the move variables from the tilt data  
 // multiply it times a speed factor 

 myBall.x += moveX * speed;
 myBall.y += moveY * speed;

}
Advertisements

One Response

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s

%d bloggers like this: