0

I've started implementing an iOS game with swift and SpriteKit.

I have an object called "bubble" which basically is an SKSpriteNode (with zPosition=0, with image) that have a child (which is an SKCropNode of a person image cropped to a circle, with zPozition=1).

That's ok if one bubble covers another bubble as a whole, but somehow it seems like the bubbles are partially covered with the person images.

a demo picture is provided: (my final output should be that bubble1 will be on top of child-of-bubble-2)

Maybe the problem is that SpriteKit ignores child ordering and just set any node with a zPozition to be in it's correct place? That is - all the bubbles are drawn first because they have zPosition=0 and then all the bubble-children are drawn, as they all have zPosition=1?

If this is the case, what can I do to make sure all bubble parts are drawn together (and other bubbles can cover that bubble, I don't care) knowing that I have a dynamic amount of bubbles?

bubbles partially cover each other

Re'em
  • 1,869
  • 1
  • 22
  • 28

2 Answers2

1

well according to this SO answer, indeed all the zPosition values are calculated before drawing.

I ended up creating a counter for bubbles, adding 1 every time a bubble has been added, and assinging the counter value as its zPosition. And inside the bubbles, I made sure every child has a zPosition in the range (0, 1)

Re'em
  • 1,869
  • 1
  • 22
  • 28
  • zPosition is relative to its parent, and then is drawn based on order in the tree hierarchy when two nodes are at an absolute equal zPosition – Knight0fDragon Mar 15 '18 at 14:59
  • 1
    in your case, your zPosition would end up being bubble1, bubble2, child1, child2. To fix this, all you would need to do is have all 4 children at zPosition 0, this way bubble1, bubble2, child1,child2 would all fall along the same absolute zPosition of 0, then going on tree hierarchy it would draw bubble1, child1, bubble2, child2 – Knight0fDragon Mar 15 '18 at 15:03
1

If you need to draw things in a precise order, then I suggest you to read section Understanding the Drawing Order for a Node Tree of SKNode Apple's documentation. Everything is correctly describe in details.

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69