Going Object-Oriented with Corona SDK and Rolly Bear World

I have been working on Rolly Bear World now for almost two months and some of my lua files are getting very crowded with code blocks and repetition of similar code patterns. In this post, we will not add any additional functionality to Rolly Bear World; but we will be restructuring some of the code and creating some Object-Oriented patterns.

Start with creating a new lua file in your project and call it fixedScene.lua. In this lua file we will add all the static scene objects of the levels: the invisible walls, the 2 bushes, the background bush, the floor, the two wooden signs, the chest, and the rock. In fixedScene.lua create a function called createStaticBackgroundElements and copy/ paste all the static elements in this function. Next create a global group variable called: myStaticgroup = display.newGroup. We need to insert each background element in this group. So we can handle the removal of these objects between scenes later via our Storyboard implementation.

Continue reading