We expanded on the SimpleLuaClasses class() concept and wrote a derivation so that our code is architected like the example below.
require "class"
Hero = class( display.newGroup )
function Hero:constructor( name, sprite )
self.name = name
self:insert( sprite )
end
function Hero:attack( target )
target:attackedBy( self )
end
function Hero:dispose()
print( 'goodbye cruel world' )
self:removeSelf()
end
Mage = class( Hero )
function Mage:attack( target )
self.\_super.attack( self, target )
self:depleteMana()
end
function Mage:depleteMana()
--deplete mana, of course. Get Caramon will you?
end
local enemy = Ogre()
local player = Mage( 'Raistlin', display.newImage( 'mage.png' ))
print( player.name ) -- Raistlin
player:attack( enemy )
player:dispose() -- goodbye cruel world
player = nil
It allows for extension of the Corona display classes, and doesn’t have that ugly mishmash of class & constructor declaration: class(function(self, param) end). So far it’s worked great. [import]uid: 4596 topic_id: 12416 reply_id: 56118[/import]