Wasn’t too sure whether to ask this in Game Development section or the General Corona section, so I’ll post it here >.<
So I was reading through Jonathan Beebe’s tutorial on modular classes; essentially, I want a game asset that is used to bounce “repel”/ bounce another object. Reason for using this method is to generally make the code more streamline; rather than manually writing a Bouncer object for every level as well as it’s functionality, I should be able to define what it is and what it can do in a seperate file, and just call that instead.
Bumper class:
local bumper = { } -- group
local bumper\_mt = { \_\_index = bumper} --metadata, required to get classes to work
-------------------------------------------------------
-- PRIVATE FUNCTIONS --
-------------------------------------------------------
-------------------------------------------------------
-- PUBLIC FUNCTIONS --
-------------------------------------------------------
-- Constructor
function bumper.new(xPos, yPos)
print("gg no re")
local bumperObj = display.newRect(0,0, 300,300)
bumperObj:setReferencePoint(display.CenterReferencePoint)
bumperObj.x = xPos; bumperObj.y = yPos;
bumperObj:setFillColor(255,0,0)
return setmetatable(bumperObj, bumper\_mt )
end
return bumper
(NOTE: the physics part isn’t done yet)
Now I can spawn this instance on to screen, it’s just that I want to be able to remove it as the scene changes. But as soon as I put this instance into a group, it doesn’t appear on screen even though the function for creating the instance is being called.
Storyboard bit:
local bumper1
function scene:createScene( event )
local group = self.view
gamebase.startGame(); -- creates scene
bumper1 = bumperClass.new( (\_W/2), (\_H/2) ) -- x position, y position
group:insert(bumper1);
end
I have a feeling that this Modular Classes method doesn’t work very well with Storyboard, but I could be wrong >.<
Thank you [import]uid: 184921 topic_id: 36236 reply_id: 336236[/import]