rezoner / CanvasQuery

Canvas for 2d gamedevelopers. Out of box canvas, keyboard, mouse, events.
http://canvasquery.com
586 stars 52 forks source link

bug fix for recursive save() and restore() #49

Closed bchoii closed 8 years ago

bchoii commented 8 years ago

html5's canvas save() and restore() supports multiple recursive calls, as in

save()
  save()
  restore()
restore()

It would be reasonable to expect CQ to also perform similarly.

But CQ's prevAlignX and prevAlignY are overwritten if cq().save() / cq().restore() is called more than once.

This change introduces a stack to store multiple prevAlign values.

rezoner commented 8 years ago

Thanks for the fix.

What do you think of align feature tho. Is it useful?

bchoii commented 8 years ago

Definitely useful. I like it. It was initially easy to get thrown off because it operates differently from other canvas libraries.

I suspect there might be another bug, if realign() was called inside of save restore().

save()
   ...
   realign()
   ...
restore()

We should probably move prevAlign.pop() outside of relign() and into restore().