Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
stage:addChild question — Gideros Forum

stage:addChild question

JackoJacko Member
edited March 2015 in General questions
How can I check if sprite is on stage?

Comments

  • piepie Member
    stage:contains(child)

    where child is the sprite you are looking for :)
  • JackoJacko Member
    I want to remove sprite after click on button and that spite isnt on stage so do i have to check if stage:contains(child)?
  • piepie Member
    Check if it exists before removing it:
    if mySprite then
     --remove mySprite
    end
  • JackoJacko Member
    What about every time addChild befor removing.
    stage:addChild(sprite)
    stage:removeChild(sprite)
    or its take memories?
  • piepie Member
    Everything takes memory, I wonder why you should add a sprite just to remove it :)

    If it is because you can't access it, maybe the reason is because it is referenced as local, and stage is missing the reference to sprite.
  • JackoJacko Member
    edited March 2015
    Its because it isnt on stage;)
  • piepie Member
    I'm missing why do you want to remove your sprite (which is not a child of stage) from stage.

    you remove a sprite from its parent:
    if its parent is stage, you remove it from stage,
    if its parent is another sprite you remove it from the other sprite.

    you can also try:
    if sprite then
    sprite:removeFromParent()
    sprite = nil
    end
  • keszeghkeszegh Member
    edited March 2015
    you may be missing that there are two parallel structures for your objects, one is the hierarchy how they are added to the stage, the other is based on object oriented programming, and is not related to stage hierarchy, objects can exist without being added to the stage or whatever. in this hierarchy one object (or rather table in case of lua) can be a subtable of another, like
    obj1=Sprite.new()
    obj1.obj2=Sprite.new()
    then you have two objects, obj1.obj2 is a subtable of obj1, but you can still build the stage hierarchy in any other way. thus in the stage it's possible to have
    stage:addChild(obj1.obj2)
    and obj1.obj2:addChild(obj1) and so in the stage obj1 is the child of obj1.obj2.

    also if you don't add them to the stage, they still exist in the memory until you e.g. nil them e.g. obj1.obj2=nil will release obj1.obj2, but e.g. obj1=nil will release both of them as nothing will reference obj1.obj2 anymore).
Sign In or Register to comment.