diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index 1292d3b717ec2b45c73924cac46ffa8e19a46b27..75aa2da1df29fccfce23155298b460029259a20c 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.