[SOLVED] Joystick tutorial, game joysticks... anything to help?

howdy all,

so since im just using HAXE/OPENFL, the first thing i look when using a game tool is to see about joysticks, and using them in-game when needed. the trouble is is that there doesnt seem to be any info on this matter, whcih really surprises me to say the least. even looking around on links that talk about joysticks [which there are very few of], i get lost in all honesty

is there any info, a tutorial is best for myself, that explains and shows joysticks in action?

i would be more than indebted to this, since joysticks are a way of life in games :wink:
im looking obviously for just HAXE/OPENFL based ones. im willing to convert things, but would rather not and just stick to what will be used

many thanks

If you use -Dlegacy, there is JoystickEvent, you listen to the stage, and handle it, similar to a mouse or keyboard event

In Lime 2, we introduced a much smarter Gamepad API, which supports connect/disconnect events, plus axes, buttons, controller mappings, etc. If you use a newer OpenFL, you can hook to this directly, or I think we should probably implement the “GameInput” API from Flash Player in OpenFL, using the Lime Gamepad API internally

aye, im on the lastest liwe, openFL, haxe.

will there be any docs on this actually. just to so people [myself included ;)] have something to work on. or if there is info online?

See the onGamepad calls here:

http://docs.openfl.org/lime/app/Module.html

This would work from OpenFL:

Lib.application.window.onGamepadAxisMove.add (function (gamepad, axis, value) {

   trace ("Gamepad " + gamepad.id + " axis " + axis + " = " + value);

});
1 Like

awesome balls. thank you so much :wink:

I also just implemented (in the source repository) a first-try at getting the Flash GameInput API implemented. Personally I like the Lime API, but this will be good for rounding it out :slight_smile:

sweet. well that code snippet you posted worked. did bring up the axis stuff. but is a nice jumping point for the buttons and the rest of the controller

i could of gone back to the older API. but i like to look ahead, and since ive only just really started using it, id prefer to use the newer stuff :wink:

again thanks :wink:

excuse for bringing up this old thread. but its much easier.

but. will the legarcy of joysticks be bought in to the newer openfl. or is this still useable from the newer one.
to be honest im still having awful trouble getting things working, even with air based tutorials.

just to ask. been bashing my head against the wall with this for so long now

thanks

okay…

so i did find something for AIR API, with using gameinput etc. but am still having this strange sensation of not being able to get things going.
it is ‘seeing’ it which is great. i think ive spent too long on this 1 thing today :wink:
but any help, id be happy :wink:

package;

import openfl.display.Sprite;
import openfl.events.GameInputEvent;
import openfl.ui.GameInputControl;
import openfl.ui.GameInputDevice;
import openfl.ui.GameInput;
import openfl.events.Event;

class Main extends Sprite {
	private var gameInput:GameInput;
	public function new(){
		super();
		gameInput = new GameInput();
		gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, controllerAdded);
		gameInput.addEventListener(GameInputEvent.DEVICE_REMOVED, controllerRemoved);
		gameInput.addEventListener(GameInputEvent.DEVICE_UNUSABLE, controllerProblem);

		this.graphics.beginFill(0xfff);
		this.graphics.drawRect(x,y,32,32);
	}

	function controllerAdded(e:GameInputEvent){
		//put code here to handle when a device is added
		trace(GameInput.numDevices);//tells you how many gamepads are plugged in
		var myDevice = GameInput.getDeviceAt(0);//1st gamepad is "0" - more gamepads would be "1", "2", "3", etc.
		trace(myDevice.numControls); //tells you how many inputs/controls the device has
		myDevice.enabled = true; //enables the device
		var cont = myDevice.getControlAt(0);//input reference (AXIS STICK, BUTTON, TRIGGER, etc) "0" is the 1st input
		trace("id: "+cont.id);//the name of this control. Ex: "AXIS_0"
		trace("value: " + cont.value); //value of this control - Axis: -1 to 1, Button: 0 OR 1, Trigger: 0 to 1
		trace("cont: " + cont.device.name); //the name of the device. ie: "XBOX 360 Controller"
		trace("device: " + cont.device);
		trace("minValue: " + cont.minValue);//the minimum possible value for the control/input
		trace("maxValue: " + cont.maxValue);//the maximum possible value for the control/input
	}


	function controllerRemoved(e:GameInputEvent){
		trace('BLAH BLAH BLAH');
	}


	function controllerProblem(e:GameInputEvent){
	 //put code here to handle when there is a problem with the controller
	}
}

holy monkey i think i have something. ill post something up soon when done. ACTUALY, i will just make an example then post it up :wink:
then everyone can have it :wink:

ok peeps,

have finally cleaned up, made slightly better, but needs some work. so if anyone has ideas, please add to them and share
but look for GAMEPAD example.
i used it with an xbox controller, and worked great

https://github.com/lewislepton/openfl-examples

page not found, your github link is not found for the gamePad example