Game Development Community

Help with IPHONE tilt control with ITGB

by Jason Oda · in iTorque 2D · 04/15/2009 (1:13 pm) · 3 replies

Someone posted this a while back. I think it's a good start to getting the tilt working on the iphone. However, as you can see below...they never got it fully working. Does anyone know what's wrong here?

It would be awesome if there were tutorials on how to integrate ALL of the iphone controls.

OLD POST:

Thanks Mat, you definetly got me in the right direction. I'm in testing mode so everything I do will be simple. I tested it with a joystick on my PC and got it to work. But when i ported over to my mac and put it on the iphone, i didn't get the desired results. Here is my code,

function startGame(%level)
{
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);

new ActionMap(moveMap);
moveMap.push();

$enableDirectInput = true;
activateDirectInput();
enableJoystick();

$iPhoneControls = "Accelerometer";

sceneWindow2D.loadLevel(%level);
}

//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}

function BallClass::onLevelLoaded(%this, %scenegraph)
{
%this.setUsesPhysics(true);
$MyPlayer = %this;

moveMap.bindCmd(joystick0, "upov", "PlayMoveUp();", "None();");
moveMap.bindCmd(joystick0, "dpov", "PlayMoveDown();", "None();");
moveMap.bindCmd(joystick0, "lpov", "PlayMoveLeft();", "None();");
moveMap.bindCmd(joystick0, "rpov", "PlayMoveRight();", "None();");

}

function PlayMoveUp()
{
$MyPlayer.setLinearVelocityY(-15);
}

function PlayMoveDown()
{
$MyPlayer.setLinearVelocityY(15);
}

function PlayMoveLeft()
{
$MyPlayer.setLinearVelocityX(-15);
}
function PlayMoveRight()
{
$MyPlayer.setLinearVelocityX(15);
}

function None()
{
$MyPlayer.setLinearVelocityX(0);
$MyPlayer.setLinearVelocityY(0);
}

#1
04/15/2009 (2:05 pm)
There may not be tutorials, but they are examples.

Check out the iPhoneTest project, and look for "oniPhoneTouchDown" for touch controls and joystick0 moveMaps (like you've got there) for accelerometer.
#2
04/15/2009 (2:19 pm)
Sorry to be a pain, but where is this? Can you post a link?
#3
04/15/2009 (3:03 pm)
No problem, just check the scripts here:

{iTGB install directory}\games\iPhoneTest\game\gameScripts\game.cs