oakmound/oak

best way to replace a renderable with a new renderable?

Closed this issue · 4 comments

currently I am doing this (simplified):

var oldR render.Renderable
event.GlobalBind( ... {
	oldR.Undraw()
	oldR, err := render.Draw(getNewR(),3)
	if err != nil {
		panic(err)
	}
}, pauseEvent}

The problem with this is that sometimes the screen updates between calling Undraw and Draw, causeing the thing I'm drawing to flicker out of existance for a frame, which is annoying.

Is their either a way to stop the screen from being updated in that time frame (perhaps something like a sync.Mutex), or is there a better way entirely to do this?

200sc commented

If you access the render.Stackable directly, you can do a Replace call on it, but there isn't an easy way to access the internals of the default stack. We could definitely add a render.Replace that acts like render.Draw with its layer management.

For current solutions, we usually use a render.Switch with string keys for anything that changes state like this regularly.

Well, I'm not using the default stack (in order to use the framerate stackable), does that help?

200sc commented

Yeah, you can call the Replace method on the heap or the stackable that you want the element drawn on.

200sc commented

We'll expose a render.Replace that works like render.Draw.