• Advertisement
Sign in to follow this  

Unity OOP Help :: Getting started with iPhone dev :: Corona / LUA

This topic is 1852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Everyone,

To keep it short so I don't bore anyone with the details, I want to begin creating games as a side project for the iPhone. I am using Corona SDK with LUA as my language and framework to work with. I am not a programmer, but I work with clients every day to assist them with integrating into our APIs for our company (I work for an online payment gateway). I am familiar and comfortable with PHP and MySQL, but I have never been able to comfortably wrap my head around object oriented design.

I am asking for some help in understanding this concept and hope that some of you from the Gamedev community can assist me with some good tutorials and explanations. I believe learning a language can be easy, but learning the core competencies which help with developing the framework of the game/application is very difficult and applies to all languages. When I try to think about how I will write the code for a game, I get frustrated because I have no idea where to start.

Dazzle me, and test me, I am not afraid of low level languages if you have good targeted tutorials.

Share this post


Link to post
Share on other sites
Advertisement
Perhaps I need to be more specific. I am choosing to learn LUA first, does anyone have any good tutorials they would like to share for this language?

Share this post


Link to post
Share on other sites
I normally recommend "[url="http://www.lua.org/pil/"]Programming in Lua[/url]" to learn the language if that helps.

Share this post


Link to post
Share on other sites
I have been reviewing this link along with some tutorials from tutplus. I actually didn't give the programming guide on Lua's site enough of a chance before moving on, but it is actually very good.

The tutorials at tutplus below are a good flash introduction for new Lua users who are looking to use the Corona SDK for mobile development. I think getting well acquainted with the language itself is important before trying to build anything with any SDK, so I will continue my reading on lua.org.

http://mobile.tutsplus.com/series/build-an-endless-runner-game-from-scratch/

Share this post


Link to post
Share on other sites
This is a topic I've been currently spending a significant amount of time on and just today found an approach that works well for me. My code up to recently has just been procedural, to get things rolling quickly, but now that my code base has started to expand enough it was time to really organize / refactor and part of that in my case meant switching to proper OOP.

First, for general Lua OOP I evaluated many different options, from the most popular (do it yourself metatable variants) to many object libraries, both obscure, amateur, and somewhat widely used.

My short list came to these two. First is MoonScript, which precompiles ".moon" files into Lua. It is a pretty radical transformation of Lua into something more like a cross between Lua and Ruby/Python. I like the syntax and the OOP aspects; in general MoonScript code is 30% smaller than Lua (which itself is already relatively small compared to languages like C++ and Java). By small, I mean low line count and low word count for the same executable functionality. MoonScript adds many of what I'd consider missing and useful features to Lua such as x += 3 and dozens of others.

If I was using Love2D, I probably would go with MoonScript (and that's what its author mostly uses it for successfully). However, for Corona, I felt debugging was somewhat more challenging. I also didn't want to really learn a language "on top of" Lua so to speak, as when I read other Lua libraries that I'm incorporating, it's like going to a different syntax. That said it is something I am highly tempted by so was a really close second choice.

At least for now, I ended up going with "middleclass" for OOP. [url="https://github.com/kikito/middleclass/blob/master/README.textile"]https://github.com/k.../README.textile[/url]

As to part of your other question, OOP design itself I'd consider somewhat language independent, and I'm not sure where to start there. The most important aspect (imo) is to make aggressive use of subclasses (aka inheritance). In other words, from a game perspective, things like: BattleDroid is a child of Robot. LongSword is a child of Weapon. KeyboardInputDatagram is a child of GameInputDatagram. GameInputDatagram is a child of EncryptedDatagram. This is definitely a paradigm shift but once you start to think in terms of objects being children of each other (instead of objects "containing" each other) it really starts to open doors to much more reusable code. It cleans up your code since you no longer see tons of complex nested if statements and that sort of thing.

A couple notes about OOP and Corona in particular. I lost a lot of time figuring out how to integrate OOP and these two methods, and here are the solutions I was able to get working.

The first is timer.performWithDelay. For this, I'll simply refer you to an article that explains the problem and solution, and an actual example from my code:

[url="http://www.coronalabs.com/blog/2012/04/24/working-with-time-delays-and-counting/"]http://www.coronalab...s-and-counting/[/url]

[source lang="plain"]timer.performWithDelay( 250, function () self.thrust_timer(self) end, 0)

function Thrust:thrust_timer ( )
if self.leftThrustIsPressed == 1 or self.leftThrustQueued == 1 then
-- ...
end[/source]




The second issue that took a lot of time for me to find a solution for ended up having a much simpler solution. That is the imageObject.addEventListener method. Without OOP, it is easy enough to use. But how do you pass in a function as an argument, that in turn can access your object instance? Here's how:

[source lang="plain"]function Thrust:initGameObjects ()
-- ...

self.left_thrust_button.owner = self
self.left_thrust_button:addEventListener("touch", self.left_thrust_button_touch)
end

function Thrust.left_thrust_button_touch ( event )
local self = event.target.owner
self.leftThrustQueued = 1
end[/source]


HTH

Share this post


Link to post
Share on other sites
Corona Labs has started a new tutorial page to help people get started wtih Lua and Corona SDK.

http://www.coronalabs.com/resources/tutorials/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By Affgoo
      https://play.google.com/store/apps/details?id=com.NE.Alien
      still a lot of work to do, but its pretty stable  please let me know what you think <3
      Atlas Sentry is a game of destroy everything. Using your turret, simply swivel and shoot your way to victory, upgrading your weapons to unleash destruction on the variety of spaceships. The bigger your combo’s the more score you get! Earn silver as you play and then purchase new weapons and abilities to better deal with your enemy. Different enemies use different tactics and weapons, work out your own priorities in their destruction order. 

      Features: 
      **2 different game modes 
      **A level select mode with 20 difficult levels including a final boss, can you defeat it? **Arcade mode of endless destruction, how long will you last? 
      **High scores to compete against others, see who can take the top spot. 
       
    • By Chamferbox
      Chamferbox, a mini game asset store has just opened with some nice game assets, 
      Here you can find a free greek statue asset 

      Also check their dragon, zombie dragon and scorpion monster out:



      They're running the Grand Opening Sale, it's 30% off for all items, but for gamedev member, you can use this coupon code:
      GRANDOPEN
      to get 50% off prices What are you waiting for, go to
      http://chamferbox.com
      and get those models now!

      View full story
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064

      View full story
    • By DevdogUnity

      Ho ho ho
      Tis the season of Christmas surprises, and we have a awesome one for you! 🎅  
      Sponsored by all your favorite Unity Asset Store developers, Nordic Game Jam, Pocket Gamer Connects, and co-hosted by Game Analytics, we (Joris and I – Devdog) are launching the second edition of our yearly Christmas Giveaway Calendar for all Unity game developers!
      You can already now sign up right here.
       
      So what’s this all about?
      For the past weeks, we’ve been collecting sponsored gifts related to Unity (asset vouchers, product keys, conference tickets etc.), and throughout each day of December leading up to Christmas Day on the 25th, we will be sending out these sponsored gifts as early gamedev Christmas presents via e-mail to hundreds of lucky winners.
      The total prize pool is at $35,000, with over 1200 presents donated by the awesome sponsors!
       
      Merry Christmas from Devdog, Game Analytics, and every single one of the sponsors.

      View full story
    • By sveta_itseez3D
      itSeez3D, a leading developer of mobile 3d scanning software, announced today a new SDK for its automatic 3D avatar generation technology, Avatar SDK for Unity. The Avatar SDK for Unity is a robust plug-n-play toolset which enables developers and creatives to integrate realistic user-generated 3D avatars into their Unity-based applications. SDK users can allow players to create their own avatars in the application or integrate the SDK into their own production processes for character design and animation.
      “Virtual avatars have recently become increasingly popular, especially in sports games and social VR apps. With the advance of VR and AR, the demand to get humans into the digital world is only increasing”, said Victor Erukhimov, itSeez3D CEO. “Our new Avatar SDK for Unity makes it super-easy to bring the avatar technology into any Unity-based game or VR/AR experience. With the Avatar SDK for Unity now every developer can bring face scanning technology into their games and allow players to create their own personalized in-game avatars, making the gameplay much more exciting and immersive.”
      Key features of the Avatar SDK for Unity:
      Automatic generation of a color 3D face model from a single selfie photo in 5-10 seconds (!). Works best with selfies, but can be used with any portrait photo.
      Shape and texture of the head model are unique for each person, synthesized with a deep learning algorithm crafted by computer vision experts
      Head models support runtime blendshape facial animations (45 different expressions)
      Generated 3D heads include eyes, mouth, and teeth
      Algorithms synthesize 3D meshes in mid-poly resolution, ~12k vertices, and ~24k triangles
      Six predefined hairstyles with hair-recoloring feature (many more available on request)
      Avatar generation API can be used in design-time and in run-time, which means you can allow users to create their own avatars in your game
      Cloud version is cross-platform, and offline version currently works on PCs with 64-bit Windows (support for more platforms is coming soon)
      Well-documented samples showcasing the functionality.
       
      Availability
      The Avatar SDK for Unity is offered in two modes - “Cloud” and “Offline”. The “Cloud” version is available at http://avatarsdk.com/ and the “Offline” version is available by request at support@itseez3d.com.
      ###
      About itSeez3D
      At itSeez3D, we are working on the computer vision technology that turns mobile devices into powerful 3D scanners. itSeez3D has developed the world's first mobile 3D scanning application that allows to create high-resolution photorealistic 3D models of people's' faces, bodies and objects. The application is available for iOS and Windows OS mobile devices powered with 3D cameras. In 2016 the company introduced Avatar SDK that creates a realistic 3D model of a face from a single selfie photo. To learn more about itSeez3D scanning software and 3D avatar creation technology, please visit www.itseez3d.com and www.avatarsdk.com.

      View full story
  • Advertisement