When it comes to business applications, it is customary to write multiple copies for each of the popular mobile platforms. This is fully justified, since the Android / iOS / etc platforms are so specific that it is quite difficult to implement on the principle of “Code at once - run everywhere”. However, the situation is quite different when it comes to mobile games. Games usually have their own style of graphic elements - buttons, menus, etc., and all graphics are built either on sprites or on 3D (note - in the future we will deal only with 2D engines). There is a completely natural desire to write an application once and collect it for different platforms.
The cross-platform MOAI framework will help us achieve this.
First of all, why MOAI? This framework was chosen purposefully. For myself, I decided that I needed an engine that:
- Cross platform
- Uses OpenGL hardware acceleration
- Game logic is implemented in a scripting language (preferably LUA)
- It should be possible to write C / C ++ extensions.
- Desirable open source. The latter was not due to the desire to save money, but the ability to edit the engine itself in the event of some critical bugs.
')
Earlier, before the choice of the framework, I hadn’t yet programmed a Loa, but the choice fell anyway on him since in its parameters it fits perfectly - it consumes little memory, has garbage collection, remarkably integrates with sishnyh applications. In the course of his study, Lua fully met his expectations, so I can say that the choice was quite successful.
Of the framework candidates, I considered Corona SDK, Gideros, Cocos2d-X (yes, it is possible to script it on Lua) and MOAI.
If you compare the Corona SDK and Gideros, then in my opinion Gideros is preferable. Since The delivery includes various tools, including a simple IDE, it is possible to write plugins, and the free mode differs from the paid one only in the presence of splash screen gideros.
The crown in the free mode puts a timeout on the assembly (but not on the emulator), besides after the launch, a dialog appears that you need to buy the Crown, then there will be no dialogue. Plug-ins can only be written after the purchase of Corona Enterprise, the price of which is not specified at all. UPD: as Lerg user wrote to me, recently their product has changed a bit:
habrahabr.ru/post/175689 But nevertheless, in some respects the Crown is better - it has a larger community, and the engine itself is also more optimized (loading sprites and .P.).
When choosing between Cocos2d-X and MOAI, I chose the latter because It was originally developed as a Lua engine.
Installation
We clone it here
github.com/moai/moai-dev or, better yet, do fork.
I do not recommend installing a binary build, because if you are not interested in modifying the engine, then most likely, try Gideros.
Next, open the project in Xcode project moai-sdk / xcode / osx / MoaiSample.xcodeproj and compile the moai binary.
Attention, desktop versions of MOAI are under Windows and Linux! But you can build an iOS project, of course, only under a poppy.
After the moai is installed, try running the example:
Go to the / usr / local / moai-sdk / samples / hello-moai directory and run the example
moai main.lua
At this point, a programmer who developed for Android or iOS should get great pleasure from the way the example is launched. It starts instantly! Without compilation, repacking and other things. I ran the example and immediately saw the result. Honestly, it's worth it!
Android
To run the application under Android or iOS, you need to create the appropriate assembly. For Android, everything is done quite simply - using the moai-sdk / ant / make-host.sh script, we create a basic Android project, the script can be used to specify additional options.
The basic project is the source code for the Android application, which contains the Moai libraries, as well as a script for packaging the final * .apk lua files, graphics and other files needed by your program.
We copy the unkown-host to the required place (I have the ~ / Projects directory), specify the path to the Android SDK in settings-local.sh:
android_sdk_root="/usr/local/android-sdk"
and the path where the main project on Lua lies
src_dirs=( "/Users/alex/Projects/myproject" )
Now, to run the application on Android, run the script run-host.sh
It must be borne in mind that the builder is quite simple - it simply takes the Android application sources, copies the MOAI project into them and assembles the apk. Those. if you need to enable accelerometer support in the application, then you need to explicitly edit MainActivity.java in the source code of the base project.
iOS
Under iOS, there is about the same mechanism, only there is no such convenient script for creating a new host. It is proposed to copy the sample project and modify it.
In principle, this is not difficult, but I personally am not comfortable when I need to pick the graphical settings of the project in Xcode.
Attention - fresh MOAI sources from the repository (which is not surprising) may contain bugs, so if you don’t build the project, then try Therefore, if you don’t want to deal with it either, then check out stable revisions (by tags) or clone my fork (https://github.com/Nepherhotep/moai-dev), which is rarely updated, and therefore more stable.
Further, the development is as follows - write and test the code on the working machine, and build for Android / iOS before you release the version.
Useful
getmoai.com - the official website of MOAI
github.com/moai/moai-dev - sources on github
github.com/ymobe/rapanui/tree/master/rapanui-sdk - a high-level framework using MOAI
github.com/derickd/moaigui - widget library for MOAI
github.com/Nepherhotep/terevaka is another high-level framework for MOAI, homemade, and with buns. Read more in my next article
habrahabr.ru/post/176771