Examples of using it from JavaScript, Flash and Java can be found in the project's examples folder; they're quite simple and documented, but in brief, to use it from JavaScript add joystick.js to your page:
<script type="text/javascript" src="joystick.js"></script>
Then create a new Joystick instance, which takes care of inserting the correct type of plug-in into the browser (ActiveX control for IE, NPAPI plug-in for everything else):
var joy = new Joystick();
That's about it! Using it in your game is a matter of reading the controller's axes and buttons wherever you would normally read the keys:
var joyX = joy.getX();
var joyY = joy.getY();
Using it from Flash is slightly more complicated due to having to access plug-ins via ExternalInterface, but the ActionScript Joystick class hides most of that away. Accessing it from a Java applet uses LiveConnect, but again the sample code takes care of this.
So, what are you waiting for? Bring on the games!

9 comments:
Is there any chance of updating this to work in Google Chrome? What would I have to do to make it work on Chrome?
Thanks,
Rich Baker
I figured it out. The Killer Sheep Sample app has a bug in the function() code for Chrome.
if (ctrlFF.setDevice(0) != null)
causes an error, but if you return ctrlFF in the catch section, everything works fine.
It was tested successfully with Chrome at the time of posting, so I guess something broke in the meantime. If you have a device connected, what does Chrome return from setDevice? Anything or does it always end up in the catch block?
Regards,
Carl
Thank you for your reply. As near as I can tell, it does not return anything. It simply winds up in the catch block.
I meant to add "afterwards". Once you have it working in Chrome (i.e. you've returned ctrlFF) what happens when you call setDevice then?
Curt,
I am sorry it took me so long to reply. We had to deploy the project and I just got back to this issue. At this point, I can not reproduce the original problem. setDevice(0) in line 172 returns TRUE.
Thank you for your help,
Rich Baker
I made a few changes to the plug-in which might solve the problem you're having with Chrome (I say *might* since I can't reproduce the error, but others have been reporting Chrome oddities and I'm hoping its related).
What needs to be installed on OS X for this to work?
It used to work in Safari but Apple changed the WebKit plug-in interface with version 10.7. It's on my list of things to fix but just not now.
Post a Comment