I think that touchscreen actions just act like mouse click and drags, so act like it's just a mouse.
As for tilting, you can use the function
getAccelerometer(); to do this.
To use the function, you declare it like so:
- Code: Select all
Vector myvector = getAccelerometer();
A vector is a special type of array we need to use for this function, make sure to capitalize the first "V".
To access the data from the Vector variable now, we use:
myvector.x, or
y, or
z.
These variables vary from the numbers
-1.0 to
1.0, and so they use decimals.
So to do something like what you want, we might use something like this (on the actor we want moving in Draw Actor):
- Code: Select all
// Declare our tilt variable.=
Vector tilt = getAccelerometer();
// The IF statements give us a "deadzone"
// so that tiny shakes when holding the device
// don't move it around
// Increase "0.2" for a bigger deadzone
if (tilt.y > 0.2)
{
// This adds to the X value of our actor based
// on how far we're tilting the device. Adjusting
// the "10" will change how sensitive it is
x = x + (tilt.y * 10);
}
// Decrease "-0.2" for a bigger deadzone
if (tilt.y < -0.2)
{
// We use "ABS" to change the currently negative
// value of "tilt.x" into a positive number,
// easier to manage.
x = x - (abs(tilt.y) * 10);
}
Of course, depending on what axis you want you'd change the
tilt.y to something else. I'm not sure which axis is which on an iPhone, since I haven't had the chance to personally test it.