android.world
Class VoidWorld

java.lang.Object
android.world.VoidWorld

public abstract class VoidWorld

extends java.lang.Object

A Class representing an imperative World and the related methods for drawing the world
and handling various events. In order to implement a functioning World you
must extend this class, and implement an onDraw
method. Other handler methods (tickRate, onTick,
onMouse, onKey, onRelease,
onOrientation, stopWhen,
and lastScene) are optional, and can be overridden to add new functionality.

See the individual methods for detailed documentation.

Extending VoidWorld

Developing an Android application is a bit more work, since it requires the
Android development kit for Eclipse. After that, you can create an
Android Project and fill in all the parameters. The World/VoidWorld classes
only require a simple hook to be added to the application's Activity.

Below is a simple example of a World that adds a new point at each mouse click. The world
contains a Scene and a new Circle is placed for each
"button-down" event received. The VoidWorld is created in the
class that extends Activity.

tickRate

Return the tick rate for this World in seconds. For example,
0.5 means two tick. The rate is only accessed when
bigBang() is initially called and the window is created.

onTick

public void onTick()

Change this World based on the Tick of the clock. This
method is called to get the update the World on each clock tick.

onMouse

public void onMouse(int x,
int y,
java.lang.String event)

Change this World when a touch event is triggered.
x and y are the location of the event on the device screen,
and event is a String that describes what kind of event
occurred.

In addition to the normal World events (button-down/up) Android devices
include a "long-button-down" event, for when the
the user does a long press (touch and hold).

Possible Mouse Events

"button-down" :

The user presses the touch screen of the device

"long-button-down" :

The user presses and holds on the touch screen of the device

"button-up" :

The user releases the touch screen of the device

"move" :

The user moves the mouse in the World window

"drag" :

The user touches and moves on the touch screen of the device

onKey

public void onKey(java.lang.String event)

Change this World when a key event is
triggered. The given event is a String that
describes which key was pressed.

Special Key

"up" :

The user presses the up-arrow key

"down" :

The user presses the down-arrow key

"left" :

The user presses the left-arrow key

"right" :

The user presses the right-arrow key

Other keys generate a single character String that
represents the key pressed. For example, Pressing the B key on
the keyboard generates "b" as an event.
If the shift key is held while pressing B then "B" is generated.

onRelease

public void onRelease(java.lang.String event)

Change this World when a key is released. The given event
is a String that describes which key was released.

Special Keys

"up" :

The user presses the up-arrow key

"down" :

The user presses the down-arrow key

"left" :

The user presses the left-arrow key

"right" :

The user presses the right-arrow key

Other keys generate a single character String that
represents the key released. For example, Pressing then releasing the B key on
the keyboard generates "b" as an onKey event and again
as an onRelease event. If the shift key is held while pressing/releasing B then "B" is generated.

onOrientation

public void onOrientation(double x,
double y,
double z)

Change this World when a device orientation event is triggered.
x, y, and z make-up the new orientation vector
for the device. When the device is resting on a flat, level surface the
orientation should be entirely in the z direction (typically
straight out the the back of the device).

If you are only concerned with the "down" angle (direction of down
with respect to the screen) you can calculate it with a method as follows: