Game Development Reference
is being discarded to help with quicker garbage collection. Next,
ll look at the two event handlers for the Accelerometer and
private function onAccelerometerUpdate(e:AccelerometerEvent):void
_ax = (_ax + e.accelerationX)/2;
_ay = (_ay - e.accelerationY)/2;
private function onEnterFrame(e:Event):void
var currentTime:Number = getTimer();
var deltaTime:Number = (currentTime - _previousTime)/1000;
_previousTime = currentTime;
Whenever an Accelerometer update occurs, the x and y values
are pulled from the resulting event and averaged with the values
stored in the engine. This will help with the sometimes erratic
jumps and spikes in the numbers returned by the device. You
may also notice that we add the value to the x acceleration but
subtract it from the y .ThisisbecauseFlash
is inverted from a typical Cartesian coordinate
plane. In traditional geometry, x values increase
as you move from left to right and y values
increase as you move up ,asshownin Fig. 15.6 .
In Flash, y values increase as you move down ,
so the values for acceleration along that axis
must also be inverted.
The onEnterFrame game loop basically acts as
the catalyst for several other methods that are
( − 3, 1)
ll look at each of these in order they
appear here, but here
s a quick summary of what
takes place every frame:
The ball is moved based on how much time
has passed since the last frame.
The engine detects all collisions with walls and
adjusts positions accordingly.
( − 1.5, − 2.5)
The engine detects any collisions with hazards
in the level.
The engine checks to see if the player has
reached their destination.
The Cartesian coordinate system.