GLBasic forum

Codesnippets => Code Snippets => Topic started by: spacefractal on 2015-Apr-12

Title: GameInput API (iOS Mfi/iCade, Android, Pandora and Windows) v1.3
Post by: spacefractal on 2015-Apr-12
Today im just got MFI Game Controllers to works in glbasic :-) for iOS7+, while iCade still working with iOS5.1.1. Button Presaures is also supported.

Rather to add them to the glbasic included JOY commands, im have dedicated to creating a another Api for it.

The reason is input behaiver for Android, iOS and Windows is quite different, and there is some incompatible between platforms with various commands, So its better to join them to use one API instead.

Button Preasure on iOS cannot been used with Joy commands, while with Android, some sticks is mapped quite different and then impossible to route them to the Joy commands. Here its easier to route them to KEY() command instead. Few Android controllers is auto mapped, but not all.

Here is the currectly supported devices and controllers:

Android :: "Ouya", "GameStick", "FireTV", "GamePad", "Keyboard"
iOS :: "iOS Gamepad", "iOS Extended", "iCade"
Windows :: "xbox", "Keyboard"
Pandora :: "Pandora"

On Android, if you plans to use RIGHT STICK and TRIGGERS, then Remapping is required for ther user. This can been done in the remapping Api as well. Checkout the Remapping class for instructions how that is done.

- xCode project Beta 5+ for iOS.
- Newer Android Extras version for Android.

Please Note:
- Android.GameControllers$() is deprecated as well, but this api works quite very similar, and easy to change it to use this api.

Release (V1.3 as 08-AUG-2015):

Yes, Android Extras sample is used as the example, which also include a GameInput API usage too. That part also works for other platforms.

Files Used:
- GameInput.gbas, Funcs_General.gbas required for include, and AndroidExtras.gbas if you compile to Android as well.
Title: Re: MFi Game Controllers on iOS and new GameInput Api
Post by: spacefractal on 2015-Apr-13
Here is how its look like with the new API:

Code: (glbasic) [Select]
GameInput.presaure=0; // Presuare is not required in Karma Miwa at all, and also want to support both iOS gamepad profiles.
GameInput.update() // update values.

// a game that support both small and big profiles can been controlled like this (here checking LEFT STICK and DPAD).

// pause // back button (this is a toggle button for all systems).
// On Android this should act as a BACK button,
// but on other systems, its should act as a PAUSE toggle.
IF GameInput.Back()=1 THEN .....

// if a device have been detached (required on iOS to detect that and on some Android devices). Its returns 1 when just attached.
// On Android, you can also checks "KEYBOARD" and "TOUCHSCREEN" from PlatformInfo$("") has been changed.
IF GameInput.isProfileChanged()=-1 THEN .....

// The first buttons (allways named "A" as on a xbox controller and MFi and most Android game controllers).
IF GameInput.ActionButton("A")=1 THEN ....

// The buttonname can changes on some controllers. They can been retrived like this (would been "X" on a Pandora example or "O" on Ouya)
IF GameInput.GetButtonName$("A") THEN ....

There is quite more functions as well of course with full gamepad profile support.
Title: Re: GameInput API (iOS Mfi/iCade, Android, Pandora and Windows) v1.3
Post by: spacefractal on 2015-Aug-03
Version 1.3 released with a small bug fixes release and cleaned up some offtype posts (include few of mine), so this thread can been clutter free. Im now explain how the remapping works and how its should been used.

Also im added a default mapping for WASD and Arrow for Windows users, which can been done by using CostumeRemapping.Defaults_Dualstick(). This function do only works for Windows. Rightstick and triggers still require user remapping on Android, if you plans to uses those.

PS. Im have cleaned up some posts to avoid clutters, include that code snippet for Android in the code snippet section, which should not been used.
Title: Re: GameInput API (iOS Mfi/iCade, Android, Pandora and Windows) v1.3
Post by: mentalthink on 2015-Aug-03
Thanks SpaceFractal, I test with an "Xbox controller" Chinesse Clone ( In fact Windows don't recognized) but Linux do it.
I test the app and works fine with this Xbox Clone, I only found 2 buttons doen't works but I'm not sure if is problem of the pad, I open a couple of times to look inside.
I think using a  .dll stay in internet can be possible to works the joystick perfectly (In fact I do with a game called Dead Light, very good about Zombies) and works really nice, only it's adding the Dll in  the same folder of the .exe

I comment because an Xbox controller cost about 40E, while this chinnese only it's about 8 or 9 Euros in China.

Title: Re: GameInput API (iOS Mfi/iCade, Android, Pandora and Windows) v1.3
Post by: spacefractal on 2015-Aug-03
im also my self uses a GameStop xbox controller. Im testing with Xbox controller on Windows because this is the most used controller most games uses today on that platform, and was used as a test controller (as least in Denmark).

m did found buttons seens to been mapped using the same scancode with those joypads im have, both on Windows and Android. Howover there can been small different on start and menu, im do not 100% sure here.

Which buttons did it not work and what was the controller name (GameInput.GetName$(1))? Also chinisse build quality in those cheap size might also reflect the price as well.
Title: Re: GameInput API (iOS Mfi/iCade, Android, Pandora and Windows) v1.3
Post by: mentalthink on 2015-Aug-04
Don't worry about my Chinesse Pad Spacefractal, (I have to test with this DLL I comment in the previous post, sure works), yes I know your Xbox pad it's the same all the people buy here, I bought the Chinnese because 8 Euros really not is money, but in Windows don't runs  :D :D , Linux see it and Wine, really extrange.

About the name , say something generic Chinnese pad... Really not it's a great problem because I think I test sometime ago directly in GLbasic, (Under Wine) and GLbasic see it.

*** When I test with the Dll I comment, but how I say don't is necessary you pick any code, in Windows don't works and I try to do anything but really Windows can't see it... Chinnese and they extrange experiment... Really I know and I see in youttube some clones working without problem, but you know 1 chinesse do joystick and 2 days later you have 100 enterprises doing the same product....

Thanks Sapaefractal for worry about it.
Title: Re: GameInput API (iOS Mfi/iCade, Android, Pandora and Windows) v1.3
Post by: spacefractal on 2015-Aug-04
this api is not a dll, just a class. Howover there is some code im uses in Java (Android) and c obj (iOS) to been connected to this code. In the next version im have removed the name check of it, so only remap it when required.