func (l *TextInstanceList) SetText(instance *render.Instance, text string, font *FontFace) (err error) { var ( img draw.Image sprite *sprites.Sprite ) if instance == nil { return // No error. } if img, err = font.GetImage(text); err != nil { return } if err = l.sheet.Pack(text, img); err != nil { // Attempt to compact the texture. if err = l.repackImage(); err != nil { return } if err = l.sheet.Pack(text, img); err != nil { return } } if sprite, err = l.sheet.Sprite(text); err != nil { return } instance.Frame = sprite.Index() instance.SetScale(sprite.WorldDimensions(l.cfg.PixelsPerUnit).Vec3(1.0)) instance.MarkChanged() instance.Key = text if err = l.generateTexture(); err != nil { return } return }
func (l *SpriteInstanceList) SetFrame(instance *render.Instance, frame string) (err error) { var s *Sprite if instance == nil { return // No error } if s, err = l.sheet.Sprite(frame); err != nil { return } instance.Frame = s.Index() instance.SetScale(s.WorldDimensions(l.pixelsPerUnit).Vec3(1.0)) instance.MarkChanged() instance.Key = frame return }