Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Reusable code snippets? — Gideros Forum

Reusable code snippets?

NinjadoodleNinjadoodle Member
edited December 2013 in General questions
Hi guys

How would I go about making reusable code snippets that I can run within scene manager levels to add things that are going to be repeated throughout?

Normally I would create functions and just run them, but since I'm using scene manager I have to use self:addChild … instead of stage:addChild …

When I try to put self:addChild inside a global function or a required lua file, I get an error, as there is no "self" to add the graphics to.

Hopefully this makes sense?

Thank you for any help :)

Comments

  • MellsMells Guru
    Accepted Answer
    Hi @Ninjadoodle

    I am not sure i understand what you're trying to achieve vut you could start by passing your scene as an argument.
     
    obj = Sprite.new()
     
    function addObjToScene(scene)
        scene:addChild(obj)
    end
     
    function MyScene:init()
        addObjToScene(self)
    end
     
    function MyScene2:init()
        addObjToScene(self)
    end
    Does that cover your needs?
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • That's pretty much exactly what I meant :)
    Thank you heaps for your help!

    I'm still getting my head around how things work in Gideros.
  • @Ninjadoodle
    You're welcome.
    I have no doubt that you will find Gideros flexible and powerful.
    Good luck with your projects :)
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.