graphics

package module
v0.0.0-...-61b0d52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 10 Imported by: 4

README

ebitengine-graphics

Build Status PkgGoDev

Overview

A package implementing various graphics primitives like Sprite for Ebitengine.

It works the best in combination with gscene package, but can be used without it.

Graphical objects list:

  • Sprite
  • Line
  • Rect
  • Container

Missing some graphical object? Tell us about it.

Installation

go get github.com/quasilyte/ebitengine-graphics

Quick Start

The most useful type of this package is Sprite, but it's tricky to demonstrate its usage without assets. This is a quick start section, it's intended to be as slim as possible.

You can use this library without gscene:

package main

import (
	"github.com/hajimehoshi/ebiten/v2"
	graphics "github.com/quasilyte/ebitengine-graphics"
	"github.com/quasilyte/gmath"
)

func main() {
	ebiten.SetWindowSize(640, 480)
	if err := ebiten.RunGame(newExampleGame()); err != nil {
		panic(err)
	}
}

type exampleGame struct {
	pos           gmath.Vec
	graphicsCache *graphics.Cache
	initialized   bool
	objects       []drawable
}

type drawable interface {
	Draw(screen *ebiten.Image)
}

func newExampleGame() *exampleGame {
	return &exampleGame{
		pos:           gmath.Vec{X: 32, Y: 32},
		graphicsCache: graphics.NewCache(),
	}
}

func (g *exampleGame) Layout(outsideWidth, outsideHeight int) (int, int) {
	return 640, 480
}

func (g *exampleGame) Draw(screen *ebiten.Image) {
	for _, o := range g.objects {
		o.Draw(screen)
	}
}

func (g *exampleGame) Update() error {
	if !g.initialized {
		g.Init()
		g.initialized = true
	}

	g.pos = g.pos.Add(gmath.Vec{X: 1, Y: 2})
	return nil
}

func (g *exampleGame) Init() {
	{
		from := gmath.Pos{Base: &g.pos}
		to := gmath.Pos{Offset: gmath.Vec{X: 128, Y: 64}}
		l := graphics.NewLine(g.graphicsCache, from, to)
		l.SetWidth(2)
		l.SetColorScale(graphics.ColorScaleFromRGBA(200, 100, 100, 255))
		g.objects = append(g.objects, l)
	}

	{
		r := graphics.NewRect(g.graphicsCache, 32, 32)
		r.Pos.Base = &g.pos
		r.SetFillColorScale(graphics.RGB(0xAABB00))
		r.SetOutlineColorScale(graphics.RGB(0x0055ff))
		r.SetOutlineWidth(2)
		g.objects = append(g.objects, r)
	}
}

With gscene it's even easier (showing only relevant part):

func (c *exampleController) Init(scene *gscene.SimpleRootScene) {
	{
		from := gmath.Pos{Base: &g.pos}
		to := gmath.Pos{Offset: gmath.Vec{X: 128, Y: 64}}
		l := graphics.NewLine(g.graphicsCache, from, to)
		l.SetWidth(2)
		l.SetColorScale(graphics.ColorScaleFromRGBA(200, 100, 100, 255))
		scene.AddGraphics(l)
	}

	{
		r := graphics.NewRect(g.graphicsCache, 32, 32)
		r.Pos.Base = &g.pos
		r.SetFillColorScale(graphics.RGB(0xAABB00))
		r.SetOutlineColorScale(graphics.RGB(0x0055ff))
		r.SetOutlineWidth(2)
		scene.AddGraphics(r)
	}
}

Note that we can add the graphical object directly to the scene. The scene will manage their Draw calls as well as their lifetimes (based on graphical objects being disposed or not).

Suggestions

Make Cache Usage Transparent

Your application only needs one instance of *graphics.Cache. It can be stored inside some app-wide context object.

Add constructor methods to that context object to hide the cache argument from the callers:

func (ctx *AppContext) NewSprite() *graphics.Sprite {
	return graphics.NewSprite(ctx.graphicsCache)
}

func (ctx *AppContext) NewRect(w, h float64) *graphics.Rect {
	return graphics.NewRect(ctx.graphicsCache, w, h)
}

// ... and so on (depending on which graphical objects you need)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlignHorizontal

type AlignHorizontal uint8
const (
	AlignHorizontalLeft AlignHorizontal = iota
	AlignHorizontalCenter
	AlignHorizontalRight
)

type AlignVertical

type AlignVertical uint8
const (
	AlignVerticalTop AlignVertical = iota
	AlignVerticalCenter
	AlignVerticalBottom
)

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a storage that is shared between all graphical elements.

Usually, there should be only 1 graphical cache per app.

func NewCache

func NewCache() *Cache

type Canvas

type Canvas struct {
	Pos gmath.Pos

	Rotation *gmath.Rad
	// contains filtered or unexported fields
}

func NewCanvas

func NewCanvas(cache *Cache) *Canvas

func (*Canvas) AddChild

func (c *Canvas) AddChild(o object)

func (*Canvas) Dispose

func (c *Canvas) Dispose()

func (*Canvas) Draw

func (c *Canvas) Draw(dst *ebiten.Image)

func (*Canvas) DrawWithOptions

func (c *Canvas) DrawWithOptions(dst *ebiten.Image, opts DrawOptions)

func (*Canvas) IsDisposed

func (c *Canvas) IsDisposed() bool

func (*Canvas) IsOffscreen

func (c *Canvas) IsOffscreen() bool

func (*Canvas) IsVisible

func (c *Canvas) IsVisible() bool

func (*Canvas) SetDstImage

func (c *Canvas) SetDstImage(img *ebiten.Image)

func (*Canvas) SetOffscreen

func (c *Canvas) SetOffscreen(offscreen bool)

func (*Canvas) SetVisibility

func (c *Canvas) SetVisibility(visible bool)

type ColorScale

type ColorScale struct {
	R float32
	G float32
	B float32
	A float32
}

ColorScale is like ebiten.ColorScale, but its values don't need to be premultiplied. In a sense, it's like color.NRGBA in comparison with color.RGBA.

For a normal color, we use {1, 1, 1, 1}, for a transparent color it's {0, 0, 0, 0}. To double the amount of red, you can use {2, 1, 1, 1} or {1, 0.5, 0.5, 1}.

Use ColorScaleFromRGBA and ColorScaleFromColor if you want to construct the color scale object easily.

func ColorScaleFromColor

func ColorScaleFromColor(c color.NRGBA) ColorScale

ColorScaleFromRGBA constructs a ColorScale using ColorScale.SetColor method.

func ColorScaleFromRGBA

func ColorScaleFromRGBA(r, g, b, a uint8) ColorScale

ColorScaleFromRGBA constructs a ColorScale using ColorScale.SetRGBA method.

func RGB

func RGB(rgb uint64) ColorScale

RGB returns a ColorScale created from the bits of rgb value. RGB(0xAABBCC) is identical to R=0xAA, G=0xBB, B=0xCC, A=0xFF.

Note: alpha value is fixed to 0xFF, if you need some other value, use RGBA() function instead.

Hint: use RGB(v).Color() to get a color.NRGBA object.

func RGBA

func RGBA(rgb uint64) ColorScale

RGBA returns a ColorScale created from the bits of rgba value. RGBA(0xAABBCCEE) is identical to R=0xAA, G=0xBB, B=0xCC, A=0xEE.

Hint: use RGBA(v).Color() to get a color.NRGBA object.

func (ColorScale) Color

func (c ColorScale) Color() color.NRGBA

Color returns the color.NRGBA representation of a color scale.

It will only work correctly for color scales those values are in [0, 1] range. If some color value overflows (or underflows) this range, the result of this operation is truncated garbage.

This function is mostly useful in combination with RGB() function to construct a color.NRGBA easily: RGB(0xAABBCCEE).Color().

func (ColorScale) RotateHue

func (c ColorScale) RotateHue(deg float32) ColorScale

RotateHue returns a color scale with its hue rotated. The argument specifies the number of degrees to rotate.

func (ColorScale) ScaleAlpha

func (c ColorScale) ScaleAlpha(x float32) ColorScale

ScaleAlpha returns the color scale with alpha multiplied by x. It doesn't affect R/G/B channels.

func (ColorScale) ScaleRGB

func (c ColorScale) ScaleRGB(x float32) ColorScale

ScaleRGB multiplies R, G and B color scale components by x. It doesn't affect the alpha channel.

func (*ColorScale) SetColor

func (c *ColorScale) SetColor(rgba color.NRGBA)

SetColor assigns the color.NRGBA equivalent to a color scale.

func (*ColorScale) SetRGBA

func (c *ColorScale) SetRGBA(r, g, b, a uint8)

SetRGBA is like SetColor, but accepts every color part separately.

type Container

type Container struct {
	Pos gmath.Pos

	Rotation *gmath.Rad
	// contains filtered or unexported fields
}

func NewContainer

func NewContainer() *Container

func (*Container) AddChild

func (c *Container) AddChild(o object)

func (*Container) Dispose

func (c *Container) Dispose()

func (*Container) Draw

func (c *Container) Draw(dst *ebiten.Image)

func (*Container) DrawWithOptions

func (c *Container) DrawWithOptions(dst *ebiten.Image, opts DrawOptions)

func (*Container) IsDisposed

func (c *Container) IsDisposed() bool

func (*Container) IsVisible

func (c *Container) IsVisible() bool

IsVisible reports whether this container is visible. Use SetVisibility to change this flag value.

If container is invisible, none of its objects will be rendered during the Draw call.

func (*Container) SetVisibility

func (c *Container) SetVisibility(visible bool)

SetVisibility changes the Visible flag value. It can be used to show or hide the container. Use IsVisible to get the current flag value.

type DrawOptions

type DrawOptions struct {
	Offset gmath.Vec

	Rotation gmath.Rad
}

type GrowHorizontal

type GrowHorizontal uint8
const (
	GrowHorizontalRight GrowHorizontal = iota
	GrowHorizontalLeft
	GrowHorizontalBoth
	GrowHorizontalNone
)

type GrowVertical

type GrowVertical uint8
const (
	GrowVerticalDown GrowVertical = iota
	GrowVerticalUp
	GrowVerticalBoth
	GrowVerticalNone
)

type Label

type Label struct {
	Pos gmath.Pos
	// contains filtered or unexported fields
}

Label is a simple text rendering object.

It supports different kinds of grow/aling settings. The text color can be changed, but only for the whole text.

Label implements gscene Graphics interface.

func NewLabel

func NewLabel(cache *Cache, ff font.Face) *Label

func (*Label) BoundsRect

func (l *Label) BoundsRect() gmath.Rect

func (*Label) Dispose

func (l *Label) Dispose()

func (*Label) Draw

func (l *Label) Draw(dst *ebiten.Image)

func (*Label) DrawWithOptions

func (l *Label) DrawWithOptions(dst *ebiten.Image, opts DrawOptions)

func (*Label) GetAlignHorizontal

func (l *Label) GetAlignHorizontal() AlignHorizontal

func (*Label) GetAlignVertical

func (l *Label) GetAlignVertical() AlignVertical

func (*Label) GetAlpha

func (l *Label) GetAlpha() float32

GetAlpha is a shorthand for GetColorScale().A expression. It's mostly provided for a symmetry with SetAlpha.

func (*Label) GetColorScale

func (l *Label) GetColorScale() ColorScale

GetColorScale is used to retrieve the current color scale value of the label's text. Use SetColorScale to change it.

func (*Label) GetGrowHorizontal

func (l *Label) GetGrowHorizontal() GrowHorizontal

func (*Label) GetGrowVertical

func (l *Label) GetGrowVertical() GrowVertical

func (*Label) GetSize

func (l *Label) GetSize() (w, h int)

func (*Label) IsDisposed

func (l *Label) IsDisposed() bool

func (*Label) IsVisible

func (l *Label) IsVisible() bool

func (*Label) SetAlignHorizontal

func (l *Label) SetAlignHorizontal(a AlignHorizontal)

func (*Label) SetAlignVertical

func (l *Label) SetAlignVertical(a AlignVertical)

func (*Label) SetAlpha

func (l *Label) SetAlpha(a float32)

SetAlpha is a convenient way to change the alpha value of the ColorScale.

func (*Label) SetColorScale

func (l *Label) SetColorScale(cs ColorScale)

SetColorScale assigns a new ColorScale to this label's text. Use GetColorScale to retrieve the current color scale.

func (*Label) SetGrowHorizontal

func (l *Label) SetGrowHorizontal(g GrowHorizontal)

func (*Label) SetGrowVertical

func (l *Label) SetGrowVertical(g GrowVertical)

func (*Label) SetSize

func (l *Label) SetSize(w, h int)

func (*Label) SetText

func (l *Label) SetText(s string)

func (*Label) SetVisibility

func (l *Label) SetVisibility(visible bool)

SetVisibility changes the Visible flag value. It can be used to show or hide the label. Use IsVisible to get the current flag value.

type Line

type Line struct {
	BeginPos gmath.Pos
	EndPos   gmath.Pos
	// contains filtered or unexported fields
}

Line is a simple 2-point line graphical primitive. Its color and width can be configured.

func NewLine

func NewLine(_ *Cache, begin, end gmath.Pos) *Line

NewLine returns a line that is drawn from begin pos to end pos. BeginPos and EndPos fields can be changed directly.

By default, a line has these properties: * Visible=true * The ColorScale is {1, 1, 1, 1} * Width is 1

func (*Line) BoundsRect

func (l *Line) BoundsRect() gmath.Rect

BoundsRect returns a rectangle that fully contains the line.

This is useful when trying to calculate whether this object is contained inside some area or not (like a camera view area).

func (*Line) Dispose

func (l *Line) Dispose()

Dispose marks this line for deletion. After calling this method, IsDisposed will report true.

func (*Line) Draw

func (l *Line) Draw(dst *ebiten.Image)

Draw renders the line onto the provided dst image.

This method is a shorthand to DrawWithOptions(dst, {}) which also implements the gscene.Graphics interface.

See DrawWithOptions for more info.

func (*Line) DrawWithOptions

func (l *Line) DrawWithOptions(dst *ebiten.Image, opts DrawOptions)

DrawWithOptions renders the line onto the provided dst image while also using the extra provided offset and other options.

The offset is applied to both begin and end positions.

func (*Line) GetAlpha

func (l *Line) GetAlpha() float32

GetAlpha is a shorthand for GetColorScale().A expression. It's mostly provided for a symmetry with SetAlpha.

func (*Line) GetColorScale

func (l *Line) GetColorScale() ColorScale

GetColorScale is used to retrieve the current color scale value of the line. Use SetColorScale to change it.

func (*Line) GetWidth

func (l *Line) GetWidth() float64

GetWidth reports the current line width. Use SetWidth to change it.

func (*Line) IsDisposed

func (l *Line) IsDisposed() bool

IsDisposed reports whether this line is marked for deletion. IsDisposed returns true only after Disposed was called on this line.

func (*Line) IsVisible

func (l *Line) IsVisible() bool

IsVisible reports whether this line is visible. Use SetVisibility to change this flag value.

When line is invisible (visible=false), it will not be rendered at all. This is an efficient way to temporarily hide a line.

func (*Line) SetAlpha

func (l *Line) SetAlpha(a float32)

SetAlpha is a convenient way to change the alpha value of the ColorScale.

func (*Line) SetColorScale

func (l *Line) SetColorScale(cs ColorScale)

SetColorScale assigns a new ColorScale to this line. Use GetColorScale to retrieve the current color scale.

func (*Line) SetVisibility

func (l *Line) SetVisibility(visible bool)

SetVisibility changes the Visible flag value. It can be used to show or hide the line. Use IsVisible to get the current flag value.

func (*Line) SetWidth

func (l *Line) SetWidth(w float64)

SetWidth changes the line width. Use GetWidth to retrieve the current line width value.

type Rect

type Rect struct {
	// Pos is a rect location binder.
	// See Pos documentation to learn how it works.
	//
	// When rendering an image, Pos.Resolve() will be used
	// to calculate the final position.
	Pos gmath.Pos
	// contains filtered or unexported fields
}

Rect is a rectangle graphical primitive.

Depending on the configuration, it's one of these:

  • Fill-only rectangle
  • Outline-only rectangle
  • Fill+outline rectangle

If you need a "texture rect", use a sprite instead.

func NewRect

func NewRect(_ *Cache, width, height float64) *Rect

NewRect returns a rectangle of the specified size. Use SetSize if you need to resize it afterwards.

By default, a rect has these properties: * Centered=true * Visible=true * The FillColorScale is {1, 1, 1, 1} * The OutlineColorScale is {0, 0, 0, 0} (invisible) * OutlineWidth is 1 (but the default outline color is invisible)

func (*Rect) BoundsRect

func (rect *Rect) BoundsRect() gmath.Rect

BoundsRect returns the properly positioned rectangle.

This is useful when trying to calculate whether this object is contained inside some area or not (like a camera view area).

func (*Rect) Dispose

func (rect *Rect) Dispose()

Dispose marks this rect for deletion. After calling this method, IsDisposed will report true.

func (*Rect) Draw

func (rect *Rect) Draw(dst *ebiten.Image)

Draw renders the rect onto the provided dst image.

This method is a shorthand to DrawWithOptions(dst, {}) which also implements the gscene.Graphics interface.

See DrawWithOptions for more info.

func (*Rect) DrawWithOptions

func (rect *Rect) DrawWithOptions(dst *ebiten.Image, opts DrawOptions)

DrawWithOptions renders the rect onto the provided dst image while also using the extra provided offset.

func (*Rect) GetFillColorScale

func (rect *Rect) GetFillColorScale() ColorScale

GetFillColorScale is used to retrieve the current fill color scale value of the rect. Use SetFillColorScale to change it.

func (*Rect) GetHeight

func (rect *Rect) GetHeight() float64

func (*Rect) GetOutlineColorScale

func (rect *Rect) GetOutlineColorScale() ColorScale

GetOutlineColorScale is used to retrieve the current outline color scale value of the rect. Use SetOutlineColorScale to change it.

func (*Rect) GetOutlineWidth

func (rect *Rect) GetOutlineWidth() float64

GetOutlineWidth reports the current outline width. Use SetOutlineWidth to change it.

func (*Rect) GetWidth

func (rect *Rect) GetWidth() float64

func (*Rect) IsCentered

func (rect *Rect) IsCentered() bool

IsCentered reports whether Centered flag is set. Use SetCentered to change this flag value.

When rect is centered, its image origin will be {w/2, h/2} during rendering.

func (*Rect) IsDisposed

func (rect *Rect) IsDisposed() bool

IsDisposed reports whether this rect is marked for deletion. IsDisposed returns true only after Disposed was called on this rect.

func (*Rect) IsVisible

func (rect *Rect) IsVisible() bool

IsVisible reports whether this rect is visible. Use SetVisibility to change this flag value.

When rect is invisible (visible=false), it will not be rendered at all. This is an efficient way to temporarily hide a rect.

func (*Rect) SetCentered

func (rect *Rect) SetCentered(centered bool)

SetCentered changes the Centered flag value. Use IsCentered to get the current flag value.

func (*Rect) SetFillColorScale

func (rect *Rect) SetFillColorScale(cs ColorScale)

SetFillColorScale assigns a new fill ColorScale to this rect. Use GetFillColorScale to retrieve the current color scale.

func (*Rect) SetHeight

func (rect *Rect) SetHeight(h float64)

func (*Rect) SetOutlineColorScale

func (rect *Rect) SetOutlineColorScale(cs ColorScale)

SetOutlineColorScale assigns a new outline ColorScale to this rect. Use GetOutlineColorScale to retrieve the current color scale.

func (*Rect) SetOutlineWidth

func (rect *Rect) SetOutlineWidth(w float64)

SetOutlineWidth changes the rect outline width. Use GetOutlineWidth to retrieve the current outline width value.

func (*Rect) SetVisibility

func (rect *Rect) SetVisibility(visible bool)

SetVisibility changes the Visible flag value. It can be used to show or hide the rect. Use IsVisible to get the current flag value.

func (*Rect) SetWidth

func (rect *Rect) SetWidth(w float64)

type Shader

type Shader struct {

	// Enabled reports whether this shader will be used during the rendering.
	Enabled bool

	Texture1 *ebiten.Image
	Texture2 *ebiten.Image
	Texture3 *ebiten.Image
	// contains filtered or unexported fields
}

Shader is an ebiten.Shader wrapper compatible with types provided by the graphics package.

Shader allocates its uniforms map lazily.

func NewShader

func NewShader(compiled *ebiten.Shader) *Shader

NewShader returns a shader wrapper. The returned shader has Enabled flag set to true.

Use Shader object fields to configure it.

func (*Shader) Clone

func (s *Shader) Clone() *Shader

Clone returns a cloned shader object. It's main purpose is to create a new shader handle that has the identical uniform values those can be modified independently.

func (*Shader) GetValue

func (s *Shader) GetValue(key string) any

GetValue returns the current uniform value stored under the key.

func (*Shader) SetFloatValue

func (s *Shader) SetFloatValue(key string, v float32)

SetFloatValue assigns float Kage uniform variable.

func (*Shader) SetIntValue

func (s *Shader) SetIntValue(key string, v int32)

SetIntValue assigns int Kage uniform variable. Since Kage uniforms are 32-bits, we use int32 here to avoid overflows.

func (*Shader) SetVec2Value

func (s *Shader) SetVec2Value(key string, v []float32)

SetVec2Value assigns vec2 Kage uniform variable. v must be a 2-element slice, otherwise this method will panic.

func (*Shader) SetVec3Value

func (s *Shader) SetVec3Value(key string, v []float32)

SetVec3Value assigns vec3 Kage uniform variable. v must be a 3-element slice, otherwise this method will panic.

type Sprite

type Sprite struct {

	// Pos is a sprite location binder.
	// See Pos documentation to learn how it works.
	//
	// When rendering an image, Pos.Resolve() will be used
	// to calculate the final position.
	Pos gmath.Pos

	// Rotation is a sprite rotation binder.
	// It's expected that sprite's rotation depends on
	// some other object rotation, hence the pointer.
	Rotation *gmath.Rad

	// Shader is an shader that will be used during rendering of the image.
	// Use NewShader to initialize this field.
	//
	// If nil, no shaders will be used.
	Shader *Shader
	// contains filtered or unexported fields
}

Sprite is a feature-rich ebiten.Image wrapper.

Sprites make many operations over the image easier. It also tries to avoid some performance pitfalls related to some edge cases of Ebitengine.

Sprite implements gscene Graphics interface.

func NewSprite

func NewSprite(cache *Cache) *Sprite

NewSprite returns an empty sprite. Use SetImage method to assign a texture to it.

By default, a sprite has these properties: * Centered=true * Visible=true * ScaleX and ScaleY are 1 * The ColorScale is {1, 1, 1, 1}

func (*Sprite) BoundsRect

func (s *Sprite) BoundsRect() gmath.Rect

BoundsRect returns the properly positioned image containing rectangle.

This is useful when trying to calculate whether this sprite is contained inside some area or not (like a camera view area).

The bounding rectangle can't be used for collisions since it treats the frame size as an object size.

func (*Sprite) Dispose

func (s *Sprite) Dispose()

Dispose marks this sprite for deletion. After calling this method, IsDisposed will report true.

Note that it's up to the scene to actually detach this sprite. This method only sets a flag but doesn't delete anything.

func (*Sprite) Draw

func (s *Sprite) Draw(dst *ebiten.Image)

Draw renders the associated image onto the provided dst image.

This method is a shorthand to DrawWithOptions(dst, {}) which also implements the gscene.Graphics interface.

See DrawWithOptions for more info.

func (*Sprite) DrawWithOptions

func (s *Sprite) DrawWithOptions(dst *ebiten.Image, opts DrawOptions)

DrawWithOptions renders the associated image onto the provided dst image while also using the extra provided offset.

func (*Sprite) GetAlpha

func (s *Sprite) GetAlpha() float32

GetAlpha is a shorthand for GetColorScale().A expression. It's mostly provided for a symmetry with SetAlpha.

func (*Sprite) GetColorScale

func (s *Sprite) GetColorScale() ColorScale

GetColorScale is used to retrieve the current color scale value of the sprite. Use SetColorScale to change it.

func (*Sprite) GetFrameHeight

func (s *Sprite) GetFrameHeight() int

GetFrameHeight returns the current frame height. Use SetFrameHeight to change it.

func (*Sprite) GetFrameOffsetX

func (s *Sprite) GetFrameOffsetX() int

GetFrameOffsetX returns the currently configured frame offset X. Use SetFrameOffsetX to change it.

func (*Sprite) GetFrameOffsetY

func (s *Sprite) GetFrameOffsetY() int

GetFrameOffsetY returns the currently configured frame offset Y. Use SetFrameOffsetY to change it.

func (*Sprite) GetFrameWidth

func (s *Sprite) GetFrameWidth() int

GetFrameWidth returns the current frame width. Use SetFrameWidth to change it.

func (*Sprite) GetImage

func (s *Sprite) GetImage() *ebiten.Image

GetImage returns the sprite's current texture image.

func (*Sprite) GetScaleX

func (s *Sprite) GetScaleX() float64

GetScaleX returns the sprite horizontal (X-axis) scaling factor. Use SetScaleX to change it.

func (*Sprite) GetScaleY

func (s *Sprite) GetScaleY() float64

GetScaleY returns the sprite vertical (Y-axis) scaling factor. Use SetScaleY to change it.

func (*Sprite) ImageHeight

func (s *Sprite) ImageHeight() int

ImageHeight returns the bound image height. The image size (width/height) can't be changed, unless a new image is assigned to the sprite.

func (*Sprite) ImageWidth

func (s *Sprite) ImageWidth() int

ImageWidth returns the bound image width. The image size (width/height) can't be changed, unless a new image is assigned to the sprite.

func (*Sprite) IsCentered

func (s *Sprite) IsCentered() bool

IsCentered reports whether Centered flag is set. Use SetCentered to change this flag value.

When sprite is centered, its image origin will be {w/2, h/2} during rendering. It also makes the sprite properly rotate around that origin point.

func (*Sprite) IsDisposed

func (s *Sprite) IsDisposed() bool

IsDisposed reports whether this sprite is marked for deletion. IsDisposed returns true only after Disposed was called on this sprite.

func (*Sprite) IsHorizontallyFlipped

func (s *Sprite) IsHorizontallyFlipped() bool

IsHorizontallyFlipped reports whether HorizontalFlip flag is set. Use SetHorizontalFlip to change this flag value.

When sprite is horizontally flipped, it's image will be mirrored horizontally.

func (*Sprite) IsVerticallyFlipped

func (s *Sprite) IsVerticallyFlipped() bool

IsVerticallyFlipped reports whether VerticalFlip flag is set. Use SetVerticalFlip to change this flag value.

When sprite is vertically flipped, it's image will be mirrored vertically.

func (*Sprite) IsVisible

func (s *Sprite) IsVisible() bool

IsVisible reports whether this sprite is visible. Use SetVisibility to change this flag value.

When sprite is invisible (visible=false), its image will not be rendered at all. This is an efficient way to temporarily hide a sprite.

func (*Sprite) SetAlpha

func (s *Sprite) SetAlpha(a float32)

SetAlpha is a convenient way to change the alpha value of the ColorScale.

func (*Sprite) SetCentered

func (s *Sprite) SetCentered(centered bool)

SetCentered changes the Centered flag value. Use IsCentered to get the current flag value.

func (*Sprite) SetColorScale

func (s *Sprite) SetColorScale(cs ColorScale)

SetColorScale assigns a new ColorScale to this sprite. Use GetColorScale to retrieve the current color scale.

func (*Sprite) SetFrameHeight

func (s *Sprite) SetFrameHeight(h int)

SetFrameHeight assigns new frame height. Use GetFrameHeight to retrieve the current value.

The frame sizes are useful when working with an underlying image that contains several logical images ("frames"). A frame size defines an image rectangle sizes to be used. A frame offset defines the rectangle Min value.

func (*Sprite) SetFrameOffsetX

func (s *Sprite) SetFrameOffsetX(x int)

SetFrameOffsetX assigns new frame X offset. Use GetFrameOffsetX to retrieve the current offset values.

The frame offsets are useful when working with an underlying image that contains several logical images ("frames"). A frame offset defines the rectangle Min value. A frame size defines an image rectangle sizes to be used.

func (*Sprite) SetFrameOffsetY

func (s *Sprite) SetFrameOffsetY(y int)

SetFrameOffsetY assigns new frame Y offset. Use GetFrameOffsetY to retrieve the current offset values.

The frame offsets are useful when working with an underlying image that contains several logical images ("frames"). A frame offset defines the rectangle Min value. A frame size defines an image rectangle sizes to be used.

func (*Sprite) SetFrameWidth

func (s *Sprite) SetFrameWidth(w int)

SetFrameWidth assigns new frame width. Use GetFrameWidth to retrieve the current value.

The frame sizes are useful when working with an underlying image that contains several logical images ("frames"). A frame size defines an image rectangle sizes to be used. A frame offset defines the rectangle Min value.

func (*Sprite) SetHorizontalFlip

func (s *Sprite) SetHorizontalFlip(hflip bool)

SetHorizontalFlip changes the HorizontalFlip flag value. Use IsHorizontallyFlipped to get the current flag value.

func (*Sprite) SetImage

func (s *Sprite) SetImage(img *ebiten.Image)

SetImage changes the image associated with a sprite.

Assigning an image sets the frame offsets to {0, 0}. The default frame width/height are image sizes.

func (*Sprite) SetScaleX

func (s *Sprite) SetScaleX(scale float64)

SetScaleX assigns new sprite horizontal (X-axis) scaling factor. Use GetScaleX to retrieve the current value.

func (*Sprite) SetScaleY

func (s *Sprite) SetScaleY(scale float64)

SetScaleY assigns new sprite vertical (Y-axis) scaling factor. Use GetScaleY to retrieve the current value.

func (*Sprite) SetVerticalFlip

func (s *Sprite) SetVerticalFlip(vflip bool)

SetVerticalFlip changes the VerticalFlip flag value. Use IsVerticallyFlipped to get the current flag value.

func (*Sprite) SetVisibility

func (s *Sprite) SetVisibility(visible bool)

SetVisibility changes the Visible flag value. It can be used to show or hide the sprite. Use IsVisible to get the current flag value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL