Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Sprite always on foreground (top) — Gideros Forum

Sprite always on foreground (top)

DikkesnoekDikkesnoek Member
edited November 2012 in General questions
Hi,

Is there a way to put a bitmap/sprite alway's on top of the hierarchy
(z-axis)? I need this to let a moving object disseapear behind an other
object. The moving object will be removed from the stage sometimes.
At the moment all the graphical child stuff will be added to the stage
and I tried the getParent and addChildAt methods but I could't get it
to work.

Regards,

Marc

Dislikes: fxone

+1 -1 (+0 / -1 )Share on Facebook

Comments

  • Whenever you add a child to a group it will always be placed at the front (on top).
    level:addChild(player)
    addOtherObjectsToParent(level)
    addMoreOtherObjectsToParent(level)
    level:addChild(player)
    Should always put player on top of other objects.
  • moopfmoopf Guru
    edited November 2012 Accepted Answer
    The best way to do this (rather than constantly re-adding the child) is to build a couple of layers in your app. On the bottom layer you have all the stuff you want to happen behind, on the top layer you have the bits you want to stay on top.

    Layers are just made by sub-classing Sprite, e.g.:
    <pre>
    MyLayer = MyLayer or Core.class(Sprite)
     
    function MyLayer:init()
       --add your bitmaps in here to 'self'
    end
     
    mylayer = MyLayer.new()
    stage:addChild(mylayer)
    So create two of those classes, one for the front and one for the back

    Likes: Mells, ar2rsawseen

    +1 -1 (+2 / -0 )Share on Facebook
  • Have you tried adding the object using
    stage:addChild(theSprite)
    will place
    theSprite
    on top of all other objects in that group.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    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
  • DikkesnoekDikkesnoek Member
    edited November 2012
    Thanks. I use the stage:addChild(theSprite). But later on, a moving sprite
    will be added again so it will be placed on top while it needs to disappear
    behind "theSprite". I will try to create dedecated layers.

    Regards,

    Marc
  • Hi guys

    I just saw this post and I'm wondering how you would use 2 layers with scenes?

    Thanks in advance!
  • @Ninjadoodle
    function scene1:init()
    	local layer1 = Sprite.new()
    	local layer2 = Sprite.new()
    	self:addChild(layer1)
    	self:addChild(layer2)
    ----now add your objects in layer1 or layer2 whatever you add in layer2 will always above the layer1
    end
  • NinjadoodleNinjadoodle Member
    edited January 2014
    Wicked!

    Thank you for that! I'm still getting my head around Groups and it took me a while to realise that you can have Groups within Groups and that Layers are also Groups :)

    Thanks again!

    Dislikes: definisto

    +1 -1 (+0 / -1 )Share on Facebook
Sign In or Register to comment.