Skip to content

Commit

Permalink
Falling back to first added texture if a user tries to draw a texture…
Browse files Browse the repository at this point in the history
… id that's not in the packer
  • Loading branch information
Allen Ray committed Aug 4, 2021
1 parent 4a75a88 commit 1840caa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packer/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ func (pack *Packer) Save(filename string) (err error) {

// Draws the given texture to the batch
func (pack *Packer) Draw(id int, m pixel.Matrix) {
sprite := pixel.NewSprite(pack.pic, pack.rects[id])
var (
srect pixel.Rect
)
if rect, has := pack.rects[id]; has {
srect = rect
} else {
srect = pack.rects[0]
}
sprite := pixel.NewSprite(pack.pic, srect)
sprite.Draw(pack.batch, m)
}

Expand Down

0 comments on commit 1840caa

Please sign in to comment.