Visualizing the Values, A Simple Animation

Must Read

Top 5 Black Friday Shopping Survival Tips

It's the hugest, silliest and craziest shopping day of the year and it's almost here. This time of year...

No Need for Concern with Bad Credit Student Loans

Bad credit student loans are available to those who would otherwise not be able to afford a college education....


Peer-to-peer (P2P) communication is the real-time transfer of data and media between clients. Real Time Media Flow Protocol (RTMFP) is...

It is not very intuitive to make sense of the accelerometer values. Let’s build an application to draw the values in a way that may clarify them.

In Figure 8-2, each axis is represented, from top to bottom, by a colored bar: green for the x-axis, red for the y-axis, and blue for the z-axis. The gray vertical line in the middle of the screen represents the zero point or rest state.

Notice that if you tilt the device in a more abrupt way, values change more rapidly. Let’s now animate objects around the screen responding in real time to the user’s motion.

A Simple Animation

Let’s create a simple animation along the x- and y-axes. A multiplier is used to boost the values so that our ball object moves around the screen at a reasonable rate:

import flash.display.Shape;
const MULTIPLIER:Number = 8.0;
var accelerometer:Accelerometer;
var ball:Shape;

The x-, y-, and z-axes, with the rest state represented by the line in the middle

ball = new Shape();;,0, 50);;
ball.x = stage.stageWidth/2;
ball.y = stage.stageHeight/2;
ball.cacheAsBitmap = true;
accelerometer = new Accelerometer();
accelerometer.addEventListener(AccelerometerEvent.UPDATE, onUpdate);
function onUpdate(event:AccelerometerEvent):void {
ball.x -= event.accelerationX * MULTIPLIER;
ball.y += event.accelerationY * MULTIPLIER;

Move your device and see how the ball follows your movement. As before, if you move in a more abrupt fashion, the ball will also move faster.

This is a good first try, but there is a lot we can do to improve responsiveness and animation.



Please enter your comment!
Please enter your name here

Latest News

Top 10 Provinces of Thailand Not to be missed for Travel

10 SuratthaniThe source of the proverbial Chaiya salted egg. Surat Thani is a province with many attractions,...

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits, even though it will have...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

More Articles Like This