accelerometer control for android

Android specific questions and discussion

accelerometer control for android

Postby ayushpal » Mon Apr 15, 2013 5:36 pm

hi ! im new here
can anyone tell me that how to make accelerometer control in a game for android device ?
for example : if i want to run my character in left direction using accelerometer , so what should i type in the script ?
ayushpal
 
Posts: 5
Joined: Sat Mar 09, 2013 4:54 am
Score: 0 Give a positive score

Re: accelerometer control for android

Postby skydereign » Mon Apr 15, 2013 8:53 pm

You can use the getAccelerometer function as described on this page. http://game-editor.com/docs/script_reference.htm
For your game though, you won't be using key events, but rather checks in the player's draw actor.
player -> Draw Actor -> Script Editor
Code: Select all
Vector v = getAccelerometer();
if(v.x>0.2) // moving right
{
    x+=5;
}
else if(v.x<-0.2)
{
    x-=5;
}

You'll need to figure out which axis are which, as this might need to use v.y instead of v.x depending on the orientation of the phone.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Android (alpha)

Who is online

Users browsing this forum: No registered users and 1 guest

cron