Skip to content

Commit

Permalink
Cached parameter added.
Browse files Browse the repository at this point in the history
  • Loading branch information
zergon321 committed Oct 1, 2021
1 parent d119f13 commit 33024fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ BasicTarget = (*Batch)(nil)
//
// Note, that if the container does not support TrianglesColor, color masking will not work.
func NewBatch(container Triangles, pic Picture) *Batch {
b := &Batch{cont: Drawer{Triangles: container, Picture: pic}}
b := &Batch{cont: Drawer{Triangles: container, Picture: pic, Cached: true}}
b.SetMatrix(IM)
b.SetColorMask(Alpha(1))
return b
Expand Down
6 changes: 5 additions & 1 deletion drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package pixel
type Drawer struct {
Triangles Triangles
Picture Picture
Cached bool

targets map[Target]*drawerTarget
allTargets []*drawerTarget
Expand Down Expand Up @@ -91,7 +92,10 @@ func (d *Drawer) Draw(t Target) {
pic := dt.pics[d.Picture]
if pic == nil {
pic = t.MakePicture(d.Picture)
dt.pics[d.Picture] = pic

if d.Cached {
dt.pics[d.Picture] = pic
}
}

pic.Draw(dt.tris)
Expand Down
9 changes: 8 additions & 1 deletion sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewSprite(pic Picture, frame Rect) *Sprite {
tri := MakeTrianglesData(6)
s := &Sprite{
tri: tri,
d: Drawer{Triangles: tri},
d: Drawer{Triangles: tri, Cached: true},
}
s.matrix = IM
s.mask = Alpha(1)
Expand All @@ -44,6 +44,13 @@ func (s *Sprite) Set(pic Picture, frame Rect) {
}
}

// SetCached makes the sprite cache all the
// incoming pictures if the argument is true, and
// doesn't make it do that if the argument is false.
func (s *Sprite) SetCached(cached bool) {
s.d.Cached = cached
}

// Picture returns the current Sprite's Picture.
func (s *Sprite) Picture() Picture {
return s.d.Picture
Expand Down
1 change: 1 addition & 0 deletions text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func New(orig pixel.Vec, atlas *Atlas) *Text {

txt.transD.Picture = txt.atlas.pic
txt.transD.Triangles = &txt.trans
txt.transD.Cached = true

txt.Clear()

Expand Down

0 comments on commit 33024fe

Please sign in to comment.