コード例 #1
0
func (l *TextInstanceList) repackImage() (err error) {
	var (
		newImage *sprites.PackedSheet
		instance *render.Instance
		sprite   *sprites.Sprite
	)
	if glog.V(1) {
		glog.Info("Repacking image")
	}
	newImage = sprites.NewPackedSheet(
		l.sheet.Width,
		l.sheet.Height,
	)
	instance = l.Head()
	for instance != nil {
		if err = newImage.Copy(instance.Key, l.sheet); err != nil {
			return
		}
		if sprite, err = newImage.Sheet.Sprite(instance.Key); err != nil {
			return
		}
		instance.Frame = sprite.Index()
		instance.MarkChanged()
		instance = instance.Next()
	}
	l.sheet = newImage
	if err = l.generateTexture(); err != nil {
		return
	}
	if glog.V(1) {
		glog.Info("Done repacking")
	}
	return
}
コード例 #2
0
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
}
コード例 #3
0
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
}