touch action

iPhone/iPod/iPad specific questions and discussion

touch action

Postby Behdadsoft » Thu Oct 03, 2013 11:42 am

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
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score

Re: touch action

Postby DarkParadox » Fri Oct 04, 2013 4:09 pm

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.
Last edited by DarkParadox on Wed Oct 23, 2013 1:05 am, edited 1 time in total.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: touch action

Postby Behdadsoft » Tue Oct 22, 2013 7:27 pm

thanks DarkParadox. :D
I test it soon.
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score


Return to iOS

Who is online

Users browsing this forum: No registered users and 1 guest

cron