Remember the Frogger series of tutorials where the same code was translated to different Frameworks? Well, there is a new version to be added to the list, this time courtesy of Luca Ferrara, and it’s a Lua version.
This is especially cool for Flash developers because Luca used a framework he’s developing (Shilke2d) that aims to port Starling to Moai, a Lua game development framework that can run on both iOS and Android.
So here is what you’ll need.
– Download the Moai SDK. br>
– Download the free ZeroBrane Studio Lua IDE. br>
– Download Shilke2d. br>
– And finally Download Luca’s port of Frogger. br>
Next comes the setup. These steps are for Mac users, but should be easily converted to Windows users.
– Inside the Shilke2D package you will find a folder called Shilke2D which is the library files. Copy and paste this folder inside the Frogger project you just downloaded. br>
– Next go to Applications or wherever you installed ZeroBranedStudio and click to show package contents. Navigate to ZeroBraneStudio/cfg/user-sample.lua and open this file in a Text Editor. br>
– Edit the path to moai excutable. Mine reads: br>
path.moai = ‘/Users/rengelbert/frameworks/moai-sdk-1.4p0/bin/osx/moai’ br>
– Edit the language used. Mine reads: br>
language = “en” br>
– Here, you can also set the path to other common frameworks like Love and Corona. br>
– Rename the file to user.lua. br>
– Open ZeroBraneStudio and open the Frogger project and its main.lua file. br>
– Then go to the menu Project|Lua Interpreter and select Moai.
– You should now be able to run the game, on Project|Run. br>
Here is a description of Shilke2D in Luca’s own words:
Shilke2D takes birth as unofficial port for MOAI / lua of the as3 Starling framework. It exposes interfaces and logics very similar to Starling, including the juggler as animator of objects that implements IAnimatable interface.
Shilke2D allows to easily move to lua and MOAI if coming from Flash / actionscript 3
development, in particular from people already used to work with Starling.
Moreover make it easy to move between the two environments when needed. Writing the frogger sample in lua was mainly just a matter of translation from as3 code.
Shilke2D differs from Starling/Flash for simpler event handling:
– events do not bubble br>
– events related to displayList changes are not handled br>
It offers a slightly more advanced tween support compared to Starling, giving default support for:
– bezier curves br>
– delay tween br>
– sequence of tweens br>
– parallel execution of more tweens (synchronized) br>
The code of frogger written for Shilke2D is mainly a translation of the original Starling code. Main differnces are in initialization phase.
Shilke2D defines specific callbacks for game execution:
– setup() called once at the beginning of the execution, as soon as shilke2D:start() is called. It’s the place where to put initialization of everything you need, like scene setup. br>
– update(elapsedTime): called every frame, replace the ENTER_FRAME event of Flash/Starling. br>
– onDirectDraw(): Called after the stage draw call, it’s used to make vectorial or debug draw. br>
– onKeyboardEvent(key,down): only on desktop platforms, it’s called whenever a key is pressed or released. br>
– touched(touch): called whenever an unhandled touch event occurs. Note that by default every touch event that hit a displayObj is handled directly by Shilke2D. br>
Frogger doesn’t need to implement a specific touched() function beacause all the touch events are handled by registered touch event handlers.