iPhone Tilt Recalibration
by Dean Parker · in iTorque 2D · 05/30/2010 (6:45 pm) · 4 replies
Has anyone had success with joystick (tilt) recalibration on the iphone and can share their code.
About the author
I started programming in early 80's on an Atari 800 and now I am coding on VS 2008 C#.
#2
I use Safari Books Online for all my tech books, and they offer a free trial period so you can read it, and see if it works for you.
If you have any question about adding it to torque I would be able to help you there.
06/14/2010 (12:11 pm)
I have just recently just read iPhone Game Development: Developing 2D & 3D games in Objective-C (Animal Guide), and they have a nice way for doing calibration. I have just implemented it into my game's next update. But I don't think I should post the code because it was one reason I read it. I use Safari Books Online for all my tech books, and they offer a free trial period so you can read it, and see if it works for you.
If you have any question about adding it to torque I would be able to help you there.
#3
Thanks for the code, that helped a lot.
Thanks for the info, much appreciated.
06/14/2010 (3:10 pm)
@ScottThanks for the code, that helped a lot.
Thanks for the info, much appreciated.
#4
The $settings::throttle variable is setup in options, from 0 - 10
07/11/2010 (7:39 am)
I ended up using the follow code.The $settings::throttle variable is setup in options, from 0 - 10
function joystickMoveX(%val)
{
$leftKey = false;
$riteKey = false;
if(%val > $settings::throttle)
$leftKey = true;
else if(%val < -$settings::throttle)
$riteKey = true;
return;
}
Torque Owner Scott Wilson-Billing
MeYuMe
The variable $GAMECONFIG::accelerometer is the sensitivity value; range is 500-600 (from memory). Default is 550.
// // iPhone Accelerometer. //////////////////////// $joyThreshold = 0.05; // Called when the player tilts the device left/right. // // Used to move the player's ship. function joystickMoveX(%val) { if ($gameState != $GAME_STATE_PLAYING) { return; } if( %val < $joyThreshold && %val > -$joyThreshold ) { %dir = 0; } else { %dir = %val * $GAMECONFIG::accelerometer; } $playerShip.setLinearVelocityX(%dir); }