Game Development Community

iTGB joystick mapping on a mac

by Eric Holsinger · in iTorque 2D · 03/11/2009 (7:50 pm) · 7 replies

My understanding is that the accelerometer maps to joystick0. If this is wrong, would someone correct me, please?

Also, based on this thread, I made a gamepad-support.cs file.

Here is what is in the file:

// Bind the functions and enable the gamepad
function setupGamePad()
{
   bindGamePadButtons();
   $enableDirectInput = "1";
   activateDirectInput();
}


//Add gamepad binds to the moveMap created in player.cs
function bindGamePadButtons()
{
   moveMap.bind(joystick0, "xaxis", joymovex); //left stick
   moveMap.bind(joystick0, "yaxis", joymovey); //left stick
   moveMap.bind(joystick0, "zaxis", joyyaw);  //right stick
   moveMap.bind(joystick0, "rzaxis", joypitch); //right stick
   moveMap.bind(joystick0, button0, joybutton0 );
   moveMap.bind(joystick0, button1, joybutton1 );
   moveMap.bind(joystick0, button2, joybutton2 );
   moveMap.bind(joystick0, button3, joybutton3 );
   moveMap.bind(joystick0, button4, joybutton4 );
   moveMap.bind(joystick0, button5, joybutton5 );
   moveMap.bind(joystick0, button6, joybutton6 );
   moveMap.bind(joystick0, button7, joybutton7 );
   moveMap.bind(joystick0, button8, joybutton8 );
   moveMap.bind(joystick0, button9, joybutton9 );
}

function joymovex(%val)
{
   if ($pref::Input::Deadzone < %val | - $pref::Input::Deadzone > %val)
   {
      echo(%val);
   }
}

function joymovey(%val)
{
   if ($pref::Input::Deadzone < %val | - $pref::Input::Deadzone > %val)
   {
	echo(%val);
   }
}


//Basic Functions - the will echo to the console and console.log so you can see what is working
//Change the function contents to whatever you want


//Right Stick
function joyyaw(%val)
{
   echo("Right stick x: "@%val);
}

function joypitch(%val)
{
   echo("Right stick y: "@%val);
}


//Buttons
function joyButton0(%val)
{
   if(%val)
   {
      echo("Button 0 pressed");
   }

   else
   {
      echo("Button 0 released");
   }
}

function joyButton1(%val)
{
   if(%val)
   {
      echo("Button 1 pressed");
   }

   else
   {
      echo("Button 1 released");
   }
}

function joyButton2(%val)
{
   if(%val)
   {
      echo("Button 2 pressed");
   }

   else
   {
      echo("Button 2 released");
   }
}

function joyButton3(%val)
{
   if(%val)
   {
      echo("Button 3 pressed");
   }

   else
   {
      echo("Button 3 released");
   }
}

function joyButton4(%val)
{
   if(%val)
   {
      echo("Button 4 pressed");
   }

   else
   {
      echo("Button 4 released");
   }
}

function joyButton5(%val)
{
   if(%val)
   {
      echo("Button 5 pressed");
   }

   else
   {
      echo("Button 5 released");
   }
}

function joyButton6(%val)
{
   if(%val)
   {
      echo("Button 6 pressed");
   }

   else
   {
      echo("Button 6 released");
   }
}

function joyButton7(%val)
{
   if(%val)
   {
      echo("Button 7 pressed");
   }

   else
   {
      echo("Button 7 released");
   }
}

function joyButton8(%val)
{
   if(%val)
   {
      echo("Button 8 pressed");
   }

   else
   {
      echo("Button 8 released");
   }
}

function joyButton9(%val)
{
   if(%val)
   {
      echo("Button 9 pressed");
   }

   else
   {
      echo("Button 9 released");
   }
}


//POV hat - //POV works with TGE 1.4 not with T2D EA build

function joyPOVUp(%val)
{
   echo("POVUp: "@%val);
}

function joyPOVDown(%val)
{
   echo("POVDown: "@%val);
}

function joyPOVLeft(%val)
{
   echo("POVLeft: "@%val);
}

function joyPOVRight(%val)
{
   echo("POVRight: "@%val);
}

I started with a new, default project. I added

exec("./gameScripts/support/gamepad-support.cs");

to the main.cs file.

I added

setupGamePad();

to game.cs right before the line for loading the level.

I also added the following to common/preferences/defaultPrefs.cs

$pref::Input::JoystickEnabled = 1;
$pref::Input::Deadzone = 0.25;
$pref::Input::Sensitivity = 1;

To test a joystick on my Mac, I have CarvWare's GamePad Companion installed, and a Philips retractable USB game pad.

Stuff is not working. O_o

My console looks like this:

Compiling /.../InputTest/game/gameScripts/game.cs...
creating path /.../InputTest/game/gameScripts/game.cs.dso
Loading compiled script /.../InputTest/game/gameScripts/game.cs.
Loading compiled script /.../InputTest/game/gameScripts/support/gamepad-support.cs.
Loading compiled script /.../InputTest/game/data/levels/untitled.t2d.
creating path /.../InputTest/common/commonConfig.xml

// somewhere around here I press ~ for console
// and then wiggle and press the gamepad like mad
// then I exit the window

Shutting down the OpenGL display device...
Cleaning up the display device...
Killing the texture manager...
Clearing the current AGL context...
Clearing the current drawable...
Deleting the rendering context...
Destroying the window...

I don't see any of the functions firing at all. Maybe I don't know where the "echo" output should go. Doesn't it go to the console?

Can anyone make any suggestions? Admittedly I don't have any images in the scene, but I figured the output should be a sufficient test to make sure this works at all.


#1
03/13/2009 (7:42 am)
I see from some other threads that joystick may not be implemented on mac for some reason. What the frick? That explains why "enableJoystick();" is not found.

Anyone added joystick support to iTGB on Mac with the SDL method from this post?
#2
10/24/2009 (8:25 am)
Quote:Anyone added joystick support to iTGB on Mac with the SDL method from this post?

Anyone?
#3
10/25/2009 (12:34 am)
Thread on the same topic from a couple of weeks ago: www.garagegames.com/community/forums/viewthread/103779

(To summarize - it doesn't work yet)
#4
10/25/2009 (5:29 am)
So how do you folks develop and mainly TEST your projects with accelerator support on a mac?

Do you compile them to the device after every minor code change?
#5
10/25/2009 (10:36 am)
You can not test it with accelerator support on the mac unless you implement such functionality actually ...
What I do is implement base functionality, testing them with regular input and develop basic controls to then switch to the device to test them "in real"
#6
10/25/2009 (4:17 pm)
I don't know if I understand this clearly:
Does this mean that you also cannot SIMULATE the implemented (joystick<->accelerator) functionality on a mac?
#7
10/25/2009 (5:16 pm)
Personally I have integrated this (exceedingly easy to do)
code.google.com/p/accelerometer-simulator/
It allows you to use your iPhone to control the accelerometer in the simulator. Very handy sometimes.