Is it possible to make something thats within a function universal to all the things connected to it? Like for example I have a function that drags a very specific set of wings and health bar follows those specific set of wings. If I went ahead and added a new set of wings and a new health bar to the mix would that function work with that new set of wings and new health bar too? I know the point of OOP is to avoid having to re-write that function for the new set of wings and health bar, How can I do that!
Well off the top of my head I have some ideas but I am not sure how If I’m right since I’ve never tried anything like this… I could put the wings in a table and do it that way. But where do I put the table? In the class itself?
I studied this blog by Jonathan Beebe and understand what its saying but can’t seem to wrap my head on what should be in the class or in the main file as for the wings and healthrect
http://blog.anscamobile.com/2011/09/tutorial-modular-classes-in-corona/
My mind is spinning so any help would really get the ball rolling for my game!
Here is an example code I was talking about…
[lua]
local healthRect = display.newRect(0,0,5,5)
healthRect:setFillColor(255,0,0)
local wings = display.newImageRect(“wings.png”, 50, 50)
wings.x = rand(100,550); wings.y = 150
wings.health = 2
local function moveMe(event)
local phase = event.phase
local x = event.x
local y = event.y
local target = event.target
if “began” == phase then
display.currentStage:setFocus(wings)
target.x0 = x
target.y0 = y
target.isFocus = true
elseif “moved” == phase and target.isFocus==true then
target.x = target.x + (x-target.x0)
target.y = target.y + (y-target.y0)
healthRect:setReferencePoint(display.TopLeftReferencePoint)
healthRect.x = target.x + (target.contentWidth/2)
healthRect.y = target.y - target.contentHeight
target.x0 = x
target.y0 = y
elseif “ended” == phase then
display.currentStage:setFocus(nil)
wings.isFocus = false
target.x0 = nil
target.y0 = nil
end
end
wings:addEventListener(“touch”,moveMe)[/lua]
THANKS FOR ANY SUGGESTIONS!! [import]uid: 51459 topic_id: 17060 reply_id: 317060[/import]