Cached parameter added.

This commit is contained in:
zergon321 2021-10-01 18:31:18 +00:00
parent d119f130f6
commit 33024feabf
4 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -23,6 +23,7 @@ package pixel
type Drawer struct {
Triangles Triangles
Picture Picture
Cached bool
targets map[Target]*drawerTarget
allTargets []*drawerTarget
@ -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)

View File

@ -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)
@ -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

View File

@ -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()