Frage

My setup:

I have a GWT Canvas that displays some grafics that rely on heavy algorithms. The objects are dragable, and therefore on drag I save everything beside the dragged object on a temporary canvas and reuse this as an image behind the dragging context.

My question: My drag canvas is a reused Canvas object, that has first to be cleared before saving the static context to it before dragging starts. I wonder if "reuse and clear" is better than "create a new canvas object".

What do you think?

Either clear canvas everytime:

private Canvas canvas;
void buffer() {
   canvas.getContext2d().clearRect(0, 0, Window.getClientWidth(), Window.getClientHeight());
   //...draw
}

...or create new object:

void buffer() {
   Canvas canvas = Canvas.createIfSupported();
   //draw
}
War es hilfreich?

Lösung

"Reuse and clear" is superior. It is more efficient since it only calls the native clearRect(x, y, w, h). There are many events that fire during the addition and removal widgets. I would use a new object only if it were a logical concept. You may also want to consider Lienzo.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top