Jump to content


Photo

Tilt different from Android to iOS


  • Please log in to reply
8 replies to this topic

#1 Thaudal

Thaudal

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 01 June 2012 - 05:10 PM

I'm doing a classic teeter-ish logic for a ball-game that uses the tilt functions. The game is in portrait mode.

On Android, this works as it should (tilt the device to make the ball roll accordingly with a speed relative to the degree of tilting)

if global.myDevice=os_android
{
 //MOVE BY TILT
 
 //X-AXIS
 if (device_get_tilt_x()>0.1)
 {
   moveX=device_get_tilt_x()
   if hspeed>-global.maxspeedX
   {
    hspeed-=moveX
   }
   myDir=1
 }
 else 
 {
  if (device_get_tilt_x()<0.1)
  {
   moveX=device_get_tilt_x()
   if hspeed<global.maxspeedX
   {
    hspeed+=-moveX
   }
  }
 }
 
 //Y-AXIS
 if (device_get_tilt_y()<0.1)
 {
  moveY=device_get_tilt_y()
  if vspeed<global.maxspeedY
  {
   if !position_meeting(x,y-radius,objLetterBallLowA)
   {
    vspeed+=moveY
   }
   else
   {
    vspeed=-vspeed/4
   }
  }
  myDir=1
 } 
 else 
 {
  if (device_get_tilt_y()>0.1)
  {
   moveY=device_get_tilt_y()
   if vspeed<global.maxspeedY
   {
    vspeed+=moveY
   }
  }
 }
}


However, on iOS, it seems to be completely inversed. So left is right, right is left, down is up and up is down.

I've tried for quite some time now inversing this, but it seems my logic is failing me. Can any of you see this a bit more clear?
  • 0

#2 Robert3DG+

Robert3DG+

    VR Games

  • GMC Member
  • 1848 posts
  • Version:GM:Studio

Posted 01 June 2012 - 05:25 PM

I haven't messed around with tilt functions yet, but as a troubleshoot are you positive you're just not holding one of the devices wrong?
  • 0

#3 Thaudal

Thaudal

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 02 June 2012 - 02:17 PM

I haven't messed around with tilt functions yet, but as a troubleshoot are you positive you're just not holding one of the devices wrong?

Yes, I am 100% positive I'm not just holding one of the devices wrong.

Please, anyone?
  • 0

#4 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3490 posts
  • Version:GM:Studio

Posted 02 June 2012 - 03:15 PM

You can use os_type constant to determine OS that game is being ran on. However, it is much better to just allow player to customize (swap) axises, as it is never completely known how axis are indexes for Android devices (variety...).
  • 0

#5 Thaudal

Thaudal

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 02 June 2012 - 04:56 PM

You can use os_type constant to determine OS that game is being ran on. However, it is much better to just allow player to customize (swap) axises, as it is never completely known how axis are indexes for Android devices (variety...).

I am already doing that. I know Android and iOS are very different - this is what my entire post is based upon. I already have an Android specific tilt function that works. It is depleted ONLY on Android using os_type. However, I also need an equivalent version of the tilt function that will be used if the OS is iOS.

My question goes: how can I inverse the code in the OP (that works as intended on Android) to do the same when the OS type is detected as iOS?
  • 0

#6 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 02 June 2012 - 08:22 PM

Just do if(os_type == os_android){ /*insert code here*/ }
if(os_type == os_ios){ /*insert inversed code here*/ } or something. I don't think its os_ios..you might have to check the help file for that one.
  • 0

#7 Thaudal

Thaudal

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 02 June 2012 - 10:29 PM

Just do if(os_type == os_android){ /*insert code here*/ }
if(os_type == os_ios){ /*insert inversed code here*/ } or something. I don't think its os_ios..you might have to check the help file for that one.


... Maybe I should've been more clear.

I know how to check where to put what version of the code.

What I need to know is how to inverse the code itself (the one I posted in the OP) to function inverse of what it does now.
  • 0

#8 Chronic

Chronic

    Administrator

  • Global Moderators
  • 2713 posts
  • Version:GM:Studio

Posted 04 June 2012 - 02:23 AM

If i'm understanding you correct the controls are working fine on android (tilt left = move left, etc) but its reversed for iOS. Correct? If so the answer is kind of obvious, just reverse your math.

instead of
hspeed -= moveX;
use
hspeed += moveX;

Btw, if you read the help file there is a very simple script to move a player around

if display_get_orientation() = display_landscape
   {
   x += sign(device_get_tilt_y());
   }
else
   {
   x += sign(device_get_tilt_x());
   }

  • 1

#9 Thaudal

Thaudal

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 04 June 2012 - 09:20 PM

If i'm understanding you correct the controls are working fine on android (tilt left = move left, etc) but its reversed for iOS. Correct? If so the answer is kind of obvious, just reverse your math.

instead of
hspeed -= moveX;
use
hspeed += moveX;

Btw, if you read the help file there is a very simple script to move a player around

if display_get_orientation() = display_landscape
   {
   x += sign(device_get_tilt_y());
   }
else
   {
   x += sign(device_get_tilt_x());
   }


I ended up using the code you suggested. It was way better anyway and is now working fully on iOS. Thank you very much. Simple suggestion, but it worked wonders, and I wouldn't have thought of it myself. :)
Rep given.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users