Sorry for the long question, I appretiate you reading this.
I have a general problem which involves my game objects and the menu bar which is on top of the screen. I have some "bullet" bitmaps which can fly in every direction, but since every time the user shoots I add a new child to the stage, the bullets end on top of the menu, which I dont want.
So to fix this, on my update function (which is called with the Event.ENTER_FRAME event) every time I add a new bullet as a child, I remove the menu and immediately add it as a child again. However the problem with this is that if i go back to the start scene (yeah I'm using ar2rs Game Template project) and then return to my game it keeps working, but if I change scene and return to my game scene a 3rd time, the "remove and then add" solution throws an error; on my remove line the error says: "The suplied sprite must be a child of the caller". I remove and add the menu like a thousand times before, I dont know why when I enter the scene for the third time it throws me this error, please help.
The menu bitmap IS being added as a child, but acording to the error it isnt.
I can't show any code cause it's too large, and when I reduce it for testing it with only two bitmaps, the error doesn't happen any more :S.
It would be good to know why this happens so I could fix it, however, another way around it would be welcome. Like for example a bitmap function that puts an image on top or behind. That would be cool actually.
Anyway, that was the question...
Comments
have you looked at addChildAt?
A simple way would be to have 2 layers, the game layer and the menu layer, keep the menu layer onTop of the game layer and keep adding your bullets to the game layer, that way it will be current in the game layer and also below the menu layer.
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
Likes: SinisterSoft
With layers you can do something like that:
You can then loop though bullets and process them as you want (technically it might be faster to process them in a table then move specific table data to the correct bullet sprite though - this depends on what you are doing).
Then add a new sprite called ui, eg ui=Sprite.new(), stage:addChild(ui). And then add your bits for your panel.
Because ui was added to stage AFTER bulllets then it will normally always be on top of bullets on screen. You can add and remove sprites to bullets and they will always be below ui (unless you change the order of things on the stage).
https://deluxepixel.com
https://deluxepixel.com
could the removeChild will auto release the sub group objects?
regards
http://giderosmobile.com/forum/discussion/comment/9441#Comment_9441
@whidbey yeah, if I put stage:removeChild(gameLayer) all of the elements added to that layer will be gone.
Likes: MoKaLux
http://giderosmobile.com/forum/discussion/480/gideros-game-template/p1
Not sure if that's what you want.
Likes: somezombiegm
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
I1m having a problem that: The supplied Sprite must be a child of the caller. I still didn't understand the structure of that 'cause every time is a different behaviour. Doesn't makes sense we add a sprite and not be able to remove that gives this error... doesn't makes any sense... I'll show an example
Likes: Paulo777
Likes: Paulo777
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
You can control when to garbage collect by using collectgarbage() like @apollo14 suggests, but this will only garbage collect sprites with no references. So long as there is one or more references to the sprite, it will never be garbage collected.
Likes: Paulo777