Hi There,
I'm new to Gideros, (but not development) and am giving it a test run... It seems quite sweet! I have a question on Gideros classes I'm hoping you all can help me on.
How do I create a non-static private member function (and non-static private members/variables)? I tried to do this in regular Lua a little while ago and could never figure it out. Everything I created as local would be static.
I have the following code - can someone point me in the right direction please? Is what I'm looking for possible with Gideros / Lua?
main_menu = Core.class(Sprite)
-- I WOULD LIKE THIS TO BE A PRIVATE, NON-STATIC MEMBER FUNCTION
function main_menu:drawBackground()
local bg = Bitmap.new(Texture.new("assets/gfx/bg1_fixed.png"))
self:addChild(bg)
end
function main_menu:init()
print ("main_menu - initialized...")
self:drawBackground()
-- add scene listners
self:addEventListener("enterBegin", self.onTransitionInBegin, self)
self:addEventListener("enterEnd", self.onTransitionInEnd, self)
self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
end
Many Thanks!!!
Comments
I don't really know how to answer the question about non-static member functions. If it is a "member" doesn't it mean it is static? Sorry, I never did learn that much cs theory so I don't know what you are trying to achieve.
My apps: http://www.yummyyellow.com
So in your quest to have them private, you will have to understand the way Lua works and the way Gideros works. Gideros loads or executes all of the files on start, so all the functions, etc are available. To have some functions/variables private as you want, here's a sample
Now you cannot assign local to any member functions as the scope is determined by the parent object. So in your case the drawBackground will have to be a non member function that can be passed the object to draw which will substitute the self object.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
For clarification, I was referring to the OOD classes usage of static and not the pure 'C' filescope description.
In the past when I have tried to create a member variable within a Lua class implementation I could never get them to behave as a member of the class, they would always act as static - I.e. change in one instance and the value would be shared by all instances!
I understand I'm not in my familiar C based language world now, which is fine but I might have to drop some of my overly anal styling views. Gonna be tough!!
Thanks again!