Which to use to develop for mobile and web?

Hi, our team have to create a game that will run on iOS and Android, but also on the web.
We are new to Cocos2d, but the developping team is more used to Lua, so we were considering Cocos2d-x with Lua for this. My questions are:

  1. If we develop it in Lua, will it be able to run nativelly on hte mobile platforms, or will it run on top of another layer for communicating with C++ or the native languages?
  2. If we develop it in Lua, will we be able to build it for iOS and Android, but also for Web? Or do we have to port it to Cocos2d-x JS? Or do we need to develop the whole game in the JS version for it to work on the web as well?
  3. If we have to develop in the JS version, will it run nativelly on the mobile platforms or will it have to run on an webapp on mobile?
  4. If we have to develop in Lua for better mobile performance and JS for Web, how much of a burden it is to port and maintain both versions?

THanks for any help.

  1. Cocos2d-x is primarily a C++ engine. I haven’t made a game with Lua, but for JS Cocos2d-x mobile games a lot of the JS code simply calls the equivalent C++ code. For example, if I create a Sprite in JS, it basically creates a Sprite in C++ and the JS sprite variable will be a reference to it. Most of the sprite’s functions I call in JS will also just call the C++ code. I imagine Lua is the same.

  2. I image the JS version of Cocos2d-x is the only one that can run in a browser, because browsers natively run JS, but not Lua or C++. The JS version of the Cocos2d-x engine is entirely written in JS (probably has some HTML and maybe CSS too) with functions that match the C++ version so that your code can call a Cocos2d-x function and get the same result regardless of if it’s running on the web or mobile. If you use Lua for mobile, you will probably need to change to JS for web, which means it’s probably easier to just use JS for everything, because the same code will run on iOS, Android and web.

  3. A JS version of the app includes both native versions to run as apps and a pure JS version that can run in the browser. So if you wanted to run it as a web app, I imagine you could, but it is possible (and preferable) to have a JS Cocos2d-x app run natively on devices.

  4. This I’m not sure about. I imagine it’s just a matter of tracking where you make changes on one version of the app and making those changes to the other version. You just might need someone who understands both Lua and Javascript to translate from one to the other. (Because both the Lua and JS versions for devices rely heavily on C++, I imagine there won’t be a huge difference in performance of Lua vs. JS. Do some research and if Lua offers very little benefit, just make you app in JS, because the version you will write for the web will run on all platforms, so there would be no need for the Lua version.)

1 Like

Thanks for the reply.

But this raises other questions. Developping in Cocos 2d-X Js, means our developer will only have to code in JS and the framework will do the work of communicating with the C++ layer? Or do we still need to code in C++?
I ask this because our developers have no experience in C++.

From what you wrote, I imagine the framework will take care of all the work, but better make sure.

Also, maybe you can help: The proccess of building for mobile and for web as well is an easy proccess? Or do we have different steps for each platform?

Is there a documentation specific for the JS version?

And I saw in this forum that there’s a Cocos 2dx HTML5 being developed. Is this the same, or better version from the JS version?

Thanks for the help

Cocos2d-html5 cocos2d-js has been merged with cocos2d-x, now if you create a js project, it will support web, mobile and desktop device at the sametime

If you choose to use js as your language of your choice, there will be still some c++ development required, especially when you want to integrate third party services. Basically you need to create js bindings before other developer can use it in js.

Ideally for your studio, it’s a good idea to have a c++ developer handle the js binding work, it’s not a lot of work actually. And rest of the developer can simply code JS. I’ve see this setup in couple of studio I visited. It’s been working out really well.

1 Like

If all the functionality you require for your app is already in Cocos2d-x, then I don’t imagine you will need to write any C++ code. Adding new functionality and, as Nite said, adding third party services, would. Some people may also choose to use C++ for some code to improve performance, but that will only be for very demanding work.

For each mobile platform, you just have to open your project and run it. So, for iOS, open the xcodeproj file in XCode and run. For mobile, you simply run index.html in a web browser. I am unsure if you have to do anything else to release the web version, although obfuscating your JavaScript files is a good idea.

Not sure about documentation. Check the Learn part up the top of this site to see.

Cocos2d-JS is the combination of Cocos2d-x and Cocos2d-HTML5 so the games made by Cocos-js can run natively on web browser and native platforms (to some extent). You still have to get to know C++ knowledge in order to fulfil diffficult tasks as well as debug your games in Xcode or VS :smiley:
If u want more help about Cocos-JS, you can contact me :smiley: Welcome!

Thanks for the help, guys.