Documentation
¶
Index ¶
- Variables
- type Camera
- type Canvaser
- type Dirtier
- type Game
- type Scene
- type Sprite
- func NewSprite(image *ebiten.Image, transform *Transform) *Sprite
- func NewSpriteAnchor(image *ebiten.Image, transform *Transform, anchor Vec2) *Sprite
- func NewSpriteAnchorSize(image *ebiten.Image, transform *Transform, anchor Vec2, width, height float64) *Sprite
- func NewSpriteSize(image *ebiten.Image, transform *Transform, width, height float64) *Sprite
- func (s *Sprite) Anchor() Vec2
- func (s *Sprite) Clean()
- func (s *Sprite) Draw(canvas Canvaser, camera Camera)
- func (s *Sprite) Height() float64
- func (s *Sprite) IsDirty() bool
- func (s *Sprite) SetAnchor(anchor Vec2)
- func (s *Sprite) SetHeight(height float64)
- func (s *Sprite) SetWidth(width float64)
- func (s *Sprite) Width() float64
- type Transform
- func (t *Transform) Clean()
- func (t *Transform) GetPosition() (float64, float64)
- func (t *Transform) IsDirty() bool
- func (t *Transform) Rotation() float64
- func (t *Transform) SetPosition(x, y float64)
- func (t *Transform) SetRotation(rotation float64)
- func (t *Transform) SetX(x float64)
- func (t *Transform) SetY(y float64)
- func (t *Transform) Translate(dx, dy float64)
- func (t *Transform) X() float64
- func (t *Transform) Y() float64
- type Vec2
- func (v Vec2) Add(other Vec2) Vec2
- func (v Vec2) Angle() float64
- func (v Vec2) Cross(other Vec2) float64
- func (v Vec2) Dist(other Vec2) float64
- func (v Vec2) Dot(other Vec2) float64
- func (v Vec2) Mag() float64
- func (v Vec2) Map(fun func(float64) float64) Vec2
- func (v Vec2) MulScalar(scalar float64) Vec2
- func (v Vec2) Normal() Vec2
- func (v Vec2) SqrDist(other Vec2) float64
- func (v Vec2) SqrMag() float64
- func (v *Vec2) String() string
- func (v Vec2) Sub(other Vec2) Vec2
- func (v Vec2) SubScalar(scalar float64) Vec2
- func (v Vec2) Unit() Vec2
- func (v Vec2) XY() (float64, float64)
Constants ¶
This section is empty.
Variables ¶
var ( // Vec2Zero is a Vec2 of (0, 0) Vec2Zero = Vec2{0, 0} // Vec2One is a Vec2 of (1, 1) Vec2One = Vec2{1, 1} )
Functions ¶
This section is empty.
Types ¶
type Camera ¶
type Camera interface { Dirtier // WorldToScreen will convert a world matrix into a screen matrix for rendering WorldToScreen(ebiten.GeoM) ebiten.GeoM // ScreenToWorld will convert an X,Y coordinate from the screen to its world position ScreenToWorld(x, y float64) (float64, float64) // IsInView returns whether or not a rectangle is within the cameras view IsInView(x, y, width, height float64) bool }
Camera allows you to move through a large scene without having to modify each individual element. To allow for any type of camera ( or none at all ) instead of defining specifics on how the camera works or behaves in relation to elements we instead define how the elements behave with the camera.
That is, if your element should interact with a possible moving camera have its world position modified to use the screen position from WorldToScreen. If your element should not be affected by a camera, such as a UI element, do not use the world to screen function.
To avoid drawing anything off screen check if it is in view first.
type Canvaser ¶
type Canvaser interface {
DrawImage(src *ebiten.Image, op *ebiten.DrawImageOptions)
}
Canvaser represents a surface that images can be drawn to. Typically, this would be an *ebiten.Image.
type Dirtier ¶
type Dirtier interface { // IsDirty returns whether or not our object is dirty IsDirty() bool // Clean the object back to a fresh state Clean() }
Dirtier allows structs to track when they are changed and only apply complex changes when there is something new to update.
type Game ¶
type Game interface { ebiten.Game // LoadScene will unload the current scene and load in a new one. // It should dipose of the previous scene before setting up the next. // This is to allow a clean transition from one scene to another by allowing the // previous scene to be disposed before the new scene is setup. // Game Logic > Dispose current scene > Setup new scene. LoadScene(Scene) }
Game adds a LoadScene method to ebitens Game interface allowing us to go from one scene to another.
type Scene ¶
type Scene interface { // Setup is used to handle all the loading of content and elements. // You should load all content and data here instead of a constructor function. // This way the LoadScene on the Game can transition between scenes. Setup(Game) // Update all game elements. Update(deltaTime float64) // Draw all game elements. Draw(screen *ebiten.Image) // Dispose of game content or data. Dispose() }
Scene is a core component of logic and rendering. The core methods are update and draw to handle game logic and rendering.
type Sprite ¶
type Sprite struct { Image *ebiten.Image Transform *Transform // contains filtered or unexported fields }
Sprite represents a renderable element in the world.
func NewSprite ¶
NewSprite will create a basic sprite from image and transform. Anchor defaults to (0,0) and size will default to the image size.
func NewSpriteAnchor ¶
NewSpriteAnchor will create a sprite with a custom anchor. Size will default to the image size.
func NewSpriteAnchorSize ¶
func NewSpriteAnchorSize( image *ebiten.Image, transform *Transform, anchor Vec2, width, height float64, ) *Sprite
NewSpriteAnchorSize will create a sprite with a custom anchor and size
func NewSpriteSize ¶
NewSpriteSize will create a sprite with a custom size. Anchor defaults to (0,0)
func (*Sprite) Clean ¶
func (s *Sprite) Clean()
Clean resets our dirty state, automatically called when drawing
func (*Sprite) Draw ¶
Draw will render the sprite onto the canvas. If our transform, sprite or camera are dirty then we will update internal values accordingly.
func (*Sprite) IsDirty ¶
IsDirty returns whether or not our internal state has changed since last drawing. When dirty our next drawing attempt will refresh drawing values.
func (*Sprite) SetAnchor ¶
SetAnchor will change our rotation point. Will also mark the sprite as dirty. (0, 0) will rotate around the top left (0.5, 0.5) will rotate around the center (1, 1) will rotate around the bottom right
func (*Sprite) SetHeight ¶
SetHeight will change our drawing height. Will also mark the sprite as dirty.
type Transform ¶
type Transform struct {
// contains filtered or unexported fields
}
Transform holds all data associated to a location
func NewTransform ¶
NewTransform will create a new transform from x,y and rotation. Note that transforms start dirty.
func (*Transform) Clean ¶
func (t *Transform) Clean()
Clean will clean up the dirty status back to false
func (*Transform) GetPosition ¶
GetPosition will return both x and y
func (*Transform) SetPosition ¶
SetPosition will change both x and y values as well as marking us as dirty.
func (*Transform) SetRotation ¶
SetRotation will change the rotation value and mark us as dirty.
type Vec2 ¶
type Vec2 struct {
X, Y float64
}
Vec2 describes a 2D vector or point
func Vec2FromAngle ¶
Vec2FromAngle returns a Vec2 from an angle in radians
func (Vec2) Map ¶
Map applies a function to both X and Y components and returns a new Vec2 of the result