[code]
local key = {}
local key_mt = { __index = key}
function key:new(startX, startY ) – constructor
local keyWidth = 25
local keyHeight = 30
local charImage = “items/img/key.png”
local k = display.newImageRect(charImage, keyWidth, keyHeight)
k.x = startX
k.y = startY
local obj = { displayObject = k }
– i suggest add the physics properties on the code that will create instances of this class
–physics.addBody(key, “static”)
return setmetatable( obj , key_mt )
end
function key:getX()
print(self.displayObject.x)
return self.displayObject.x
end
– would i add collision event handlers here?
– try this. to add collision:
– nameOfObject:addEventListener(‘collision’, nameOfObject)
function key:collision(event)
– do stuff
end