From c61b677fa92681e1139c7597491345b702d62e2b Mon Sep 17 00:00:00 2001 From: faiface Date: Wed, 12 Apr 2017 16:02:39 +0200 Subject: [PATCH] fix Canvas.Draw --- pixelgl/canvas.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index 1292d3b..75aa2da 100644 --- a/pixelgl/canvas.go +++ b/pixelgl/canvas.go @@ -54,8 +54,6 @@ func NewCanvas(bounds pixel.Rect) *Canvas { }) c.shader = shader - c.sprite = pixel.NewSprite(c, c.Bounds()) - return c } @@ -121,7 +119,11 @@ func (c *Canvas) SetComposeMethod(cmp pixel.ComposeMethod) { // SetBounds resizes the Canvas to the new bounds. Old content will be preserved. func (c *Canvas) SetBounds(bounds pixel.Rect) { c.gf.SetBounds(bounds) + if c.sprite == nil { + c.sprite = pixel.NewSprite(nil, pixel.Rect{}) + } c.sprite.Set(c, c.Bounds()) + c.sprite.SetMatrix(pixel.IM.Moved(c.Bounds().Center())) } // Bounds returns the rectangular bounds of the Canvas.