camera

package
v0.0.0-...-b7bdad3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	Target   Target
	MaxDist  float64
	MaxSpeed float64
	Ease     geo.EaseFn
	// Shaker is optional. Set its fields and call the Camera's StartShake functions. If
	// Shaker.Falloff is nil then the Shaker's ShakeConst is used.
	Shaker geo.Shaker
	// contains filtered or unexported fields
}

Camera manages a 2-D camera. If its distance from Target is greater than MaxDist when Update is called then its position is moved directly toward the target so that the distance is equal to MaxDist. If the Camera is less than MaxDist then its velocity is directly toward the Target with a magnitude that is a percentage of MaxSpeed determined by the Ease function. The Ease function is given the ratio <distance to Target>/MaxDist and the return value is multiplied by MaxSpeed.

func New

func New(width, height int) *Camera

New creates, initializes, and returns a new Camera. The parameters width and height are the dimensions of the image tha Camera will be used to draw to. The default Ease fuction is linear, MaxSpeed=0, and MaxDist=0. This results in perfectly sticking to the Target, though MaxDist=0 on its own is sufficient for that behavior.

func (*Camera) Center

func (c *Camera) Center() geo.Vec

Center returns the camera's center position in world coordinates.

func (*Camera) ScreenCoords

func (c *Camera) ScreenCoords(pos geo.Vec) geo.Vec

ScreenCoords takes a position in world coordinates and returns its position on the screen.

func (*Camera) StartShake

func (c *Camera) StartShake()

StartShake restarts the Shaker time.

func (*Camera) Update

func (c *Camera) Update(dt time.Duration)

Update updates the Camera's state simulating dt time passed.

func (*Camera) WorldCoords

func (c *Camera) WorldCoords(pos geo.Vec) geo.Vec

WorldCoords takes a position in screen coordinates and returns its position in the world.

type Target

type Target interface {
	Pos() geo.Vec
}

Target is any object that has a function for returning a position that the Camera can use as a target position.

Jump to

Keyboard shortcuts

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