Page 1 of 1

touch action

PostPosted: Thu Oct 03, 2013 11:42 am
by Behdadsoft
Hi.

I want make shooter game for iPhone, but I want when touch the screen player can shoot and when rotate iPhone to right or left, character can move. how can do it?

Thanks

Re: touch action

PostPosted: Fri Oct 04, 2013 4:09 pm
by DarkParadox
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.

Re: touch action

PostPosted: Tue Oct 22, 2013 7:27 pm
by Behdadsoft
thanks DarkParadox. :D
I test it soon.