1 registered members (henrybane),
1,182
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to use XBox Controller with Gamestudio
[Re: thegamedesigner]
#285988
08/22/09 03:18
08/22/09 03:18
|
Joined: Apr 2009
Posts: 27 Silicon Valley
Dillinger
Newbie
|
Newbie
Joined: Apr 2009
Posts: 27
Silicon Valley
|
Sure, no problem Gamestudio already has generic joystick support built in, which is pretty much what the XBox controller uses since it needed to be compatible with a lot of already existing games. All you'll need is an XBox to USB adaptor. You can find many different models on eBay. I recommend the X-Joy Converter (Xbox to PC/MAC USB Controller Adapter). This link should bring one up : Generic eBay Search for X-Joy Convertor Since it is a Microsoft product, it integrates pretty seemlessly with .NET game authoring tools. I got it for XNA using C#, but found C# to be unbelievably verbose, so I switched to Gamestudio. There's lots of them on eBay that require the breakaway cord. I like this one cause you plug straight in to the USB adaptor. I just plugged it into the USB and Windows went online and found the XBox driver automatically. Here is some quick sample code to test it out. Some of the recommended code for a standard joystick controller doesn't seem to do anything. I commented that bit out. Also, everything seemed to show up except the trigger and Dpad buttons. Perhaps somebody can figure out how to get those bits working. Here's what I've got so far:
// XBoxController.c
// Tutorials in Plain English by Dillinger 2009 :)
#include <acknex.h>
#include <default.c>
var Xbox_Joystick_X , Xbox_Joystick_Y ; // Change var to float for higher sensitivity
var Xbox_Joystick_Raw_X , Xbox_Joystick_Raw_Y,
Xbox_Joystick_Rot_X, Xbox_Joystick_Rot_Y ;
// var Xbox_Joystick2_Raw_X , Xbox_Joystick2_Raw_Y ;
var Xbox_Button_A, Xbox_Button_B, Xbox_Button_X, Xbox_Button_Y,
Xbox_Button_Front_L, Xbox_Button_Front_R, Xbox_Button_Back, Xbox_Button_Start,
Xbox_Joy_Push_L, Xbox_Joy_Push_R, Xbox_Button_11, Xbox_Button_12 ;
PANEL* Xbox_Variables =
{
digits( 60, 10, "XBox Controller Variables", Arial#28b, 1, 0 ) ;
digits( 60, 40, "Xbox_Joystick_X = %0.f", Arial#18b, 1, Xbox_Joystick_X ) ;
digits( 60, 60, "Xbox_Joystick_Y = %0.f", Arial#18b, 1, Xbox_Joystick_Y ) ;
digits( 60, 80, "Green A Button = %0.f", Arial#18b, 1, Xbox_Button_A ) ;
digits( 60, 100, "Red B Button = %0.f", Arial#18b, 1, Xbox_Button_B ) ;
digits( 60, 120, "Blue X Button = %0.f", Arial#18b, 1, Xbox_Button_X ) ;
digits( 60, 140, "Yellow Y Button = %0.f", Arial#18b, 1, Xbox_Button_Y ) ;
digits( 60, 160, "Front Left Button = %0.f", Arial#18b, 1, Xbox_Button_Front_L ) ;
digits( 60, 180, "Front Right Button = %0.f", Arial#18b, 1, Xbox_Button_Front_R ) ;
digits( 60, 200, "Back Button = %0.f", Arial#18b, 1, Xbox_Button_Back ) ;
digits( 60, 220, "Start Button = %0.f", Arial#18b, 1, Xbox_Button_Start ) ;
digits( 60, 240, "Push Joystick Left = %0.f", Arial#18b, 1, Xbox_Joy_Push_L ) ;
digits( 60, 260, "Push Joystick Right = %0.f", Arial#18b, 1, Xbox_Joy_Push_R ) ;
// digits( 60, 280, "Xbox_Button_11 = %0.f", Arial#18b, 1, Xbox_Button_11 ) ;
// digits( 60, 300, "Xbox_Button_12 = %0.f", Arial#18b, 1, Xbox_Button_12 ) ;
digits( 60, 320, "Joystick Left Raw X = %0.f", Arial#18b, 1, Xbox_Joystick_Raw_X ) ;
digits( 60, 340, "Joystick Left Raw Y = %0.f", Arial#18b, 1, Xbox_Joystick_Raw_Y ) ;
digits( 60, 360, "Joystick Right Raw X = %0.f", Arial#18b, 1, Xbox_Joystick_Rot_X ) ;
digits( 60, 380, "Joystick Right Raw Y = %0.f", Arial#18b, 1, Xbox_Joystick_Rot_Y ) ;
// digits( 60, 400, "Xbox_Joystick2_Raw_X = %0.f", Arial#18b, 1, Xbox_Joystick2_Raw_X ) ;
// digits( 60, 420, "Xbox_Joystick2_Raw_Y = %0.f", Arial#18b, 1, Xbox_Joystick2_Raw_Y ) ;
red = 255 ; green = 255 ; blue = 255 ; // Change Text color
flags = VISIBLE ;
}
function main()
{
level_load ("") ; // Tell the engine to load a Level, then suddenly change your mind
wait (1) ; // Give it a little time to think about that one
while( 1 ) // as long as the sun rises in the East...
{ // copy everything to temp variables for display purposes
Xbox_Joystick_X = joy_force.x ;
Xbox_Joystick_Y = joy_force.y ;
Xbox_Joystick_Raw_X = joy_raw.x ;
Xbox_Joystick_Raw_Y = joy_raw.y ;
Xbox_Joystick_Rot_X = joy_rot.y ; // X = Y ?? It Works. Go Figure.
Xbox_Joystick_Rot_Y = joy_rot.x ;
Xbox_Button_A = joy_1 ;
Xbox_Button_B = joy_2 ;
Xbox_Button_X = joy_3 ;
Xbox_Button_Y = joy_4 ;
Xbox_Button_Front_L = joy_5 ;
Xbox_Button_Front_R = joy_6 ;
Xbox_Button_Back = joy_7 ;
Xbox_Button_Start = joy_8 ;
Xbox_Joy_Push_L = joy_9 ;
Xbox_Joy_Push_R = joy_10 ;
// Xbox_Button_11 = joy_11 ;
// Xbox_Button_12 = joy_12 ;
// Xbox_Joystick2_Raw_X = joy2_raw.x ;
// Xbox_Joystick2_Raw_Y = joy2_raw.y ;
wait(1);
}
}
Sorry I couldn't get the answer to you before your big presentation.
Last edited by Dillinger; 08/22/09 03:37.
|
|
|
Re: How to use XBox Controller with Gamestudio
[Re: Dillinger]
#294186
10/16/09 20:47
10/16/09 20:47
|
Joined: Jul 2009
Posts: 1,198 Berlin, Germany
Liamissimo
Serious User
|
Serious User
Joined: Jul 2009
Posts: 1,198
Berlin, Germany
|
Okay, so I also want to add it. I Played around with the Code and I think I'll get something useful:) So, here is what I got until now:P
#include <acknex.h>
#include <default.c>
ENTITY* box;
var Xbox_Joystick_X , Xbox_Joystick_Y ; // Change var to float for higher sensitivity
var Xbox_Joystick_Raw_X , Xbox_Joystick_Raw_Y,
Xbox_Joystick_Rot_X, Xbox_Joystick_Rot_Y ;
// var Xbox_Joystick2_Raw_X , Xbox_Joystick2_Raw_Y ;
var Xbox_Button_A, Xbox_Button_B, Xbox_Button_X, Xbox_Button_Y,
Xbox_Button_Front_L, Xbox_Button_Front_R, Xbox_Button_Back, Xbox_Button_Start,
Xbox_Joy_Push_L, Xbox_Joy_Push_R, Xbox_Button_11, Xbox_Button_12 ;
function main()
{
level_load ("") ; // Tell the engine to load a Level, then suddenly change your mind
wait (1) ; // Give it a little time to think about that one
box = ent_create("cube.mdl", nullvector, NULL);
while( 1 ) // as long as the sun rises in the East...
{ // copy everything to temp variables for display purposes
Xbox_Joystick_Y = joy_force.x ;
Xbox_Joystick_X = joy_force.y ;
box.y = joy_force.x;
box.x = joy_force.y;
wait(1);
}
}
So, but if you change for example the camera, the ball also changes the direction. Littel bit confused but thanks for making this big script:)
"Ich weiss nicht genau, was Sie vorhaben, aber Sie können keine Triggerzonen durch Ihr Level kullern lassen." -JCL, 2011
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|