Array

Visualizing the Values, A Simple Animation

Must Read

Canon 7D Motion and Depth of Field

There are distinct characteristics that are related to changes in aperture and shutter speed. Shutter speed controls the length...

California Home Equity Loans – Disadvantages of Using Your Home’s Equity

Because of home equity loans, homeowners have the opportunity to tap into their home's equity and acquire extra cash....

Canon PowerShot G12, Shooting with an External Flash

One feature that sets the G12 apart from most point-and-shoots is also one that most G12 owners will likely...

Business blogging – an effective part of your online strategy

Blogging has come a long way since the term was originally in 1999 as a shortened form of the...

Internet Marketing Tips – Are You Running A Black Friday Sale?

Well, with Black Friday coming up, have you given any thought to running a Black Friday sale? No? You...

I Need a Mortgage Quote to Refinance My Home – 3 Tips For Getting The Best Rate

Being able to make payments on your mortgage each month is a good feeling. It means that you are...
Admin
test

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();
ball.graphics.beginFill(0xFF9900);
ball.graphics.drawCircle(0,0, 50);
ball.graphics.endFill();
ball.x = stage.stageWidth/2;
ball.y = stage.stageHeight/2;
ball.cacheAsBitmap = true;
addChild(ball);
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.

 

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost...

More Articles Like This