Child `h2d.Graphics` disappears when the parent added for the second time

Is this a bug or I’m missing something in the way h2d.Graphics should be used?

Here’s an example that reproduces this:

Pressing SPACE will remove/add from/to s2d the same h2d.Object that contains a h2d.Tile (red background) and h2d.Graphics (green circle) in it. After the Object once removed and attached for the second time the Graphics object isn’t visible while Tile is still there. Looks as if it was disposed at the moment the parent object was removed from it’s parent.

UPD: Forgot to mention: I’m using git version of heaps, haxe v4.1.4 on linux

This is by design. Removing an object from scene implies their disposal, and in case of Graphics - it disposes of all its contents.

Interesting. Is there a way to change this behavior? I guess I can just change visibility of an object instead of completely removing it from the graph.

No, not really. In the first place, Graphics are not really designed to be the primary class for rendering of your game, there’s SpriteBatch, TileGroup and Bitmap for that plus you can easily make your own optimal renderers. You can’t really circumvent disposal of Graphics, and your best bet is to just either hide it or move it into a separate hidden Object in the scene tree. With latter you also can override container sync and cause Graphics to not receive any updates until its reintroduced into the visible part of the Scene.

1 Like

Ok, thank you!
I was using Graphics only for placeholder graphics so I wasn’t intending to use it in production. Anyway knowing that removing a node from the graph in Heaps implies its disposal is important for choosing approaches in future. Thanks!