ControlsOverlay.js: An option for touch controls in Cocos2d-HTML5 applications

Hello all,

I’m in the process of making some tutorials for Cocos2d-HTML5 specifically focused on the BlackBerry PlayBook and BlackBerry 10. I created a virtual controls system so that making Joysticks and Buttons was simplified (my initial tutorials revolve around a game; shocker I know.) :slight_smile:

In any case, full articles are coming, but I wanted to share the source in case anybody was interested in checking it out:
https://github.com/oros/ControlsOverlay.js

There is a Documentation folder with a PDF that describes how to use the framework.

If anybody has any questions about it, or ends up using it, I would be ecstatic to hear how it goes! If anybody sees anything that could use improvements, I’m absolutely happy to take recommendations too.

DISCLAIMER: This is not implemented using the Cocos2d-HTML5 framework ‘touch’ functions. It is using standard HTML5 touch listeners that get assigned to your

element. Due to issues I encountered in my development I had to take that approach. Good news is that it’s not very different, and once we’re able to get unique touch identifiers with Cocos2d-HTML5 on the BlackBerry PlayBook / BlackBerry 10, it won’t be that tricky to convert ControlsOverlay.js to use the standard Cocos2d-HTML5 events instead. But for the time being, that’s the workaround I needed to use.

Thanks Erik, it is cool!:wink:

You had brought us a cool virtue controls.

I would like to have a try if any games are developed by it.

Absolutely, it’s a completely new framework that I made for my tutorials so I doubt it has any usage yet, but if someone does end up using it I’d be ecstatic to see it!

I currently have 3 tutorials working through publication (Getting Started, Virtual Controls, and Sprite Animation), the latter uses this framework to move an animated (running) Sprite around the screen with buttons to make him take some actions (swing sword, block, cheer, etc.)

I’ll definitely post those tutorials in this thread once they’re published, just need to get all the reviews done. The ultimate goal is to put together a full-fledged game sample that would leverage these controls too. Perhaps, in the interim, I’ll make a pong clone or something smaller to show some real usage. If anyone wants to provide some brainstorm ideas for a basic app, feel free to post here and I’ll try to make it happen :slight_smile:

Hi Erik,

I have downloaded the whole project, but when i run index.html joystick is not working….I am having Windows machine and i am running it on a browser…I am beginner in the cocos2d-html….is there any extra thing to do …

Please guide me , i wanna implement it in my game…

Thanks in advance…
Mangesh

Hello Mangesh,

Which browser are you using? My guess is that since the framework implements touch events, the mouse events of the browser aren’t being converted over. Some browser, like Chrome, let you simulate touch events. To do this you can:
* Right-click in the web page and select Inspect Element. This will bring up the Web Inspector controls.
* In the bottom-right corner, there is a little gear icon for options, click that.
* In the Overrides tab, scroll to the bottom and enable Emulate Touch Events

Then, when you have Web Inspector open and you click on the screen, the click should also emulate a touch event.

The other approach is to use the Ripple Extension for Chrome, which emulates mobile device behaviour including touch events on clicks.

In addition to the above, I would also recommend the more up-to-date Freewill.js from my BoxQuest sample:

https://github.com/blackberry/BB10-WebWorks-Community-Samples/tree/master/BoxQuest

The one thing with BoxQuest is that it requires a BlackBerry device, but check the comments here to disable the BlackBerry requirement:

https://github.com/blackberry/BB10-WebWorks-Community-Samples/blob/master/BoxQuest/index.html#L63

And if you want Cocos2d-HTML5 keyboard controls, check the following two:

https://github.com/blackberry/BB10-WebWorks-Community-Samples/blob/master/BoxQuest/js/SceneStart.js#L37
https://github.com/blackberry/BB10-WebWorks-Community-Samples/blob/master/BoxQuest/js/SceneStart.js#L163

Hi Erik,

Thanks for help…

Actually there was issue with browser…

When i Run on Simulator on MAC and Emulator on Windows….

It works AWESOMELY…

It is very nice …

Now I want to implement box2D in my Game…is there any js file or any link which can guide me to do this…

Thanks
Mangesh

Hi Mangesh,

That BoxQuest sample I noted actually has a Web Worker implementation for Box2DWeb.

https://github.com/blackberry/BB10-WebWorks-Community-Samples/tree/master/BoxQuest

I’m in the middle of writing a detailed blog post on it, but I would recommend BoxQuest as a starting point. It’s a full-on Cocos2d-HTML5, Freewill.js, and Box2DWeb implementation. The places to start would be SceneStart.js, showing how to initialize the Web Worker, and how to pass data from the main application thread to the Web Worker:

https://github.com/blackberry/BB10-WebWorks-Community-Samples/blob/master/BoxQuest/js/SceneStart.js

And the actual Web Worker file that implements the framework and processes physics:

https://github.com/blackberry/BB10-WebWorks-Community-Samples/blob/master/BoxQuest/js/Box2dWebWorker.js

The main benefit of using a Web Worker is that you get the processing without interference. I actually hit issues using the scheduleUpdate approach, I think there were some timing issues between the rendering and physics calculations at the root of it. Using Web Workers resolved that issue.

There is also a very awesome line of tutorials created by Seth Ladd on his blog regarding Box2DWeb, and there is a great compilation listing them here:

Hi Erik,

Thanks for help… :slight_smile:

I will go through it…

and let u know about that, i know it will be one of the best just like the way u implemented the joystick…

Keep posting the tutorials to guide us. :slight_smile:

Thanks
Mangesh