12-23-2013 06:18 AM - edited 12-23-2013 06:21 AM
I've trying to implement gamepad support in my HTML5 game. I've noticed that it would be impossible in WebWorks, so I've converted the app to Hybrid.
Unfortunately, despite many attempts I haven't managed to receive screen events in Cascades. I'm pretty shure I've tried all available methods:
- subcalssing Application and implementing the virtual "event" method
- using QAbstractEventDispather
- implementing (subclassing) AbstractBpsEventHandler
- using "InstallEventFilter" method
- using foreign window control
The only way that actually allowed me to receive all screen events (with gamepad events) was to call screen_request_events on cascades screen context:
Window * win = app->mainWindow(); screen_window_t winHandle = win->handle(); void* screenContextVoid; screen_get_window_property_pv(winHandle, SCREEN_PROPERTY_CONTEXT, &screenContextVoid); screen_context_t screenContext = (screen_context_t)screenContextVoid; subscribe(screen_get_domain()); bps_initialize(); screen_request_events(screenContext);
but that brakes cascades screen handling (controls stop to work). I'm guessing that cascades message loop handles screen events using libscreen events and that's why I broke it with the bps request call?
ForeignWindowControl also gave some hope, but it seems it only receives screen events if the window has focus.
Does anyone have any other ideas how it could be done?
12-23-2013 07:48 AM
I've actually been looking into the same, both for a hybrid game and a cascades only. But I see you've come further than I did already. I'll be following the topic for other replies, and if needed help as a tester.
I wonder if we can write a libary/custom element that will allow the user to read the gamepad events.
12-23-2013 02:22 PM
Actually, a community member has been working on a webworks gamepad extension. You can check it out here: http://supportforums.blackberry.com/t5/Web-and-Web
It's open source, so you can see how it was done if you were curious.
12-23-2013 02:55 PM
Wow, I'm shocked! This is smart - instead of listening for events, the code continuously checks gamepad state to see if something changed.
This should be easily ported to cascades.
Thanks for your help !