User Input for Desktop Systems

Hey guys,

I am planning to develop a game that can run on desktop systems. win32 is my main choice, but still be able to port to other desktop systems easily would be nice. I noticed a lack of user input features in Cocos2d-x, and have some questions about it.

MOUSE: I see a few mouse event functions under MacEventDelegate, is there any more? Is there any mouse handling functions for win32? And if so, can they handle and use mice that have more than three buttons?

KEYBOARD: I noticed that QWERTY support is coming in the next beta (http://www.cocos2d-x.org/issues/1501) which is fantastic! How extensive will this be? Can I use all the keys on the keyboard, like the arrow keys and function keys?

GAMEPAD / JOYSTICK: Is there any plans to implement joystick support? Or maybe someone has already implemented it into Cocos2d-x that is not merged with the main version?

I like to give the user complete flexibility, and should be able to map any button to any action, whether this button is on a joystick, mouse, or a key on the keyboard. How possible is this in the latest version of Cocos2d-x?
Anything that can help me is greatly appreciated! Thanks,

  • Ryan

(P.S. Why is distribution (NOT development) on Linux no longer supported?)

Hello,

I agree this is something essential.

On our side, we have hooked SDL input support into a custom Win32 main loop, it does the job (Game running with gamepad, mouse, keyboard on win32) but the design is ugly.
Plus relying on SDL is probably the lazy options, and adds a fat dependency to Cocos-2D-X.

Any other ideas/suggestions ?

Yesterday I asked a similar question, but specifically about a callback function for mouse movement, and got not reply. Asking on other forums, I confirmed what I had discovered from digging the code, there isn’t a way to do it. It seems that, since Cocos is aimed for mobile platforms, some standard concepts from Desktop (such as a pointer/mouse) aren’t implemented. For mouse movement (and I suppose, for keyboard/gamepad/joystick) you could try using the update()/sheduleUpdate() (which is what I’m using). It’s not the as some function being called upon user input, but it’s the best you can get at this point without making changes to the default WinProc function.

Then the default WindowProc should be modified to give a user callback.
A clean way to do it is having a delegate such as UserWndProc(……) which does nothing by default, and that we could override somewhere in user code.

Romain TISSERAND wrote:

Hello,
>
I agree this is something essential.
>
On our side, we have hooked SDL input support into a custom Win32 main loop, it does the job (Game running with gamepad, mouse, keyboard on win32) but the design is ugly.
Plus relying on SDL is probably the lazy options, and adds a fat dependency to Cocos-2D-X.
>
Any other ideas/suggestions ?

This is indeed something essential if Cocos2dx wants to promote themselves as being able to create desktop games. I was thinking about using some media framework such as SDL or SFML (http://www.sfml-dev.org/). However I did not like the idea of adding another framework in to the game. As you mentioned, it’s not the best design and shouldn’t really be necessary in the first place! I was learning towards using SFML since it is divided neatly into five modules. Since they are independent, I could just package the one module that deals with input with my game, cutting out 4/5’s of the framework in my build. Again I shouldn’t be having to rely on another media framework, but it should work.

I was then thinking, for windows games at least, of using DirectInput (http://msdn.microsoft.com/en-us/library/windows/desktop/ee416853(v=vs.85).aspx) for joystick support and this (http://msdn.microsoft.com/en-us/library/windows/desktop/ms632585(v=vs.85).aspx) for mouse and keyboard support. Excuse my ignorance as I have not looked into it too much, but it may seem too low level and too much hard work to implement these with Cocos2dx. I’m still not sure about this approach, though.

Hugo Souza wrote:

Yesterday I asked a similar question, but specifically about a callback function for mouse movement, and got not reply. Asking on other forums, I confirmed what I had discovered from digging the code, there isn’t a way to do it. It seems that, since Cocos is aimed for mobile platforms, some standard concepts from Desktop (such as a pointer/mouse) aren’t implemented. For mouse movement (and I suppose, for keyboard/gamepad/joystick) you could try using the update()/sheduleUpdate() (which is what I’m using). It’s not the as some function being called upon user input, but it’s the best you can get at this point without making changes to the default WinProc function.

I understand that Cocos2d is aimed at mobile platforms, but I was not expecting a huge lack of nearly compulsory features was surprising. I honestly took user input functionality for granted, and just assumed it was implemented. Don’t get me wrong, it’s still a great engine, but I was disappointed, as well as surprised, in this area.

Sorry to both that I will not be able to contribute in the WindowProc conversation, as I have not yet started developing on this engine and therefore have no knowledge on this, just yet. I hope steps are made in the right direction.

  • Ryan

Being able to override WindowProc is the first step of handling standard Win32 messages such as mouse, keyboard and touch-panel input (API added in Windows 7), resizing windows, and more.

I agree that DirectInput is overkill, but it’s probably the proper way to do it in Cocos2DX.
There’s a library call DDHidLib in OSX which does more or less what DirectInput does, which is useful too. Already used it in another (non-cocos2dx) Mac App Store game with success.

The trick we used is to use SDL initializing it with only input subsystem.
It works quite well on Win32 and OSX.

Ok, I think I will just use the input module from SFML then. It will do until there is a better solution out there.

Thanks!

Ryan Kerswill wrote:

(P.S. Why is distribution (NOT development) on Linux no longer supported?)

Why you belive it?
I can read on the wiki page this text part only:
With cocos2d-x framework, developers can easily create or port their games onto iOS, Android, Bada, BlackBerry Qnx, Marmalade, WindowsXP/Windows7, Linux and Windows8 Metro.

For the Input question:
Do you know about this extension:

Hello all,
I’m working on a multiplatform game and I need a good support for input.
I work a lot with OIS (http://en.wikipedia.org/wiki/Object_Oriented_Input_System), it is stable, multiplatform and well designed…

You say it’s better if I think of a way to integrate it into cocos2d-x? :stuck_out_tongue:

OIS actually have some design bugs [1]. Also it works only on Windows and Linux, last release comes from 2010. It does not mean that cocos2d itself have no poorly designed APIs, of course.

[1] https://github.com/zinnschlag/openmw/pull/925

I use OIS also in iOS and OsX, through macPorts.
I used in the past also for Wii…