Skip to content

Instantly share code, notes, and snippets.

@vib3oh
vib3oh / OOP-Animal.lua
Created February 15, 2013 03:47
These snippets are described in detail as part of the Object-Oriented Lua Tutorial available at: http://www.ardentkid.com/blog/from-zero-to-oo-ardentkids-guide-to-object-oriented-lua-with-corona-sdk
--Classes/Objects/Animal.lua
local scene = scene
local Super = require('Classes.Object')
local Animal = Class(Super) --inherits Object Class
--INSTANCE FUNCTIONS
function Animal:initialize(img)
--calls parent Class's initialize()
--with "self" as this instance
function character:enterFrame(event)
--Get speed and angle
local speed = self.speed or 0
local angle = self.angle or 0
--Claculate x-y distances
local xval = math.cos(angle) * speed
local yval = -math.sin(angle) * speed
--Move the character's group/ sprite/ image
--WITHOUT CLOSURE
function character:enterFrame(event)
local speed = self.speed or 0
local angle = self.angle or 0
local xval = math.cos(angle) * speed
local yval = -math.sin(angle) * speed
self.group:translate(xval, yval)
function character:move()
--Localized variables and function calls
local mCos, mSin = math.cos, math.sin
local group = self.group
--Closure enterFrame
local function onEachFrame(event)
local speed = self.speed or 0
local angle = self.angle or 0
### Keybase proof
I hereby claim:
* I am omidahourai on github.
* I am omidahourai (https://keybase.io/omidahourai) on keybase.
* I have a public key ASCeZXQLzyC_PXdWkSt556zirWKEaqBNf85ArSIWBOq-Fgo
To claim this, I am signing this object: