Game Development Reference
In-Depth Information
Figure 15.1 The FrameRate
Profiler, used in SpaceRocks,
currently reflects 100% of the
intended frame rate. As
performance lessened, the
green bar would shrink,
revealing a white bar
underneath.
allows you to know the orientation of the device in 3D space and
respond to movement. In this example, we
ll create a game that
uses the accelerometer as the primary means of input. It
'
salso
worth noting that this game will be intended for the iPhone in par-
ticular, so it will make use of a fixed screen aspect ratio and resolu-
tion.InChapter16,whenwecreateanAndroidgame,we
'
'
ll make
sure that the game supports multiple screen sizes.
The Accelerometer Class
Flash CS5 has an extremely simple class for interfacing with a
mobile device
s accelerometer. If you want to read values from the
device, you simply instantiate a new Accelerometer object and lis-
ten for its UPDATE event.
'
import flash.events.AccelerometerEvent;
import flash.sensors.Accelerometer;
var accelerometer:Accelerometer = new Accelerometer();
accelerometer.addEventListener(AccelerometerEvent.UPDATE,
onAccelerometerUpdate, false, 0, true);
function onAccelerometerUpdate(e:AccelerometerEvent):void
{
}
In this case, the onAccelerometerUpdate method will be called
on creating the listener (to establish the initial orientation of the
device), and then afterwards at a fixed interval. You can define this
Search Nedrilad ::




Custom Search