Wednesday, May 4, 2011

Following the Penelope tutorial Part 1

I started the Penelope tutorial a week ago. The touch input method is really unfamiliar to me. After reached page 31 of the tutorial, I stop there and starting to learn more in depth about the objects and function calls, because the tutorial manual is not down to the detail very deeply.

The first thing is about access the screen, there is an object "GUITexture" to deal with the touch input.

gui = GetComponent(GUITexture);

That is the texture image of the thumb pad, in addition, the pixelInset member variable store the location and dimension of the image on screen, that means, chaning gui.pixelInset.x and gui.pixelInset.y will alter the location of the image on the screen.

The second thing is how to access the input on screen, the Input class and its methods deal with both normal input (keyboard/mouse/joystick) as well as touch input.

For instance, the Input.touchCount return the number of touches, Input.touches return the list of touched objects during the last frame. Input.acceleration and Input.accelerationEvents deal with accelerometer I think.

By using Input.touchCount to get the number of touches, using Input.GetTouch(int x) in a loop to get the Touch objects of each touch.

Example:
var count : int = Input.touchCount;
for (var i : int = 0; i < count; i++) {
  var touch : Touch = Input.GetTouch(i);
}

Touch object is a struct which has several variables. For example

fingerId
The unique index for touch.
position
The position of the touch.
deltaPosition
The position delta since last change.
deltaTime
Amount of time passed since last change.
tapCount
Number of taps.
phase
Describes the phase of the touch.

Input.GetTouch(int x).position return the Vector2 variable;

Input.GetTouch(int x).phase return the Enumeration of TouchPhase

Began
A finger touched the screen.
Moved
A finger moved on the screen.
Stationary
A finger is touching the screen but hasn't moved.
Ended
A finger was lifted from the screen. This is the final phase of a touch.
Canceled
The system cancelled tracking for the touch, as when (for example) the user puts the device to her face or more than five touches happened simultaneously. This is the final phase of a touch.

No comments:

Post a Comment