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.
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
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.
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 layer1end
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
Comments
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Layers are just made by sub-classing Sprite, e.g.:
Likes: Mells, ar2rsawseen
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
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
I just saw this post and I'm wondering how you would use 2 layers with scenes?
Thanks in advance!
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