engo

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 16 Imported by: 159

README

Engo

GoDoc License Build Status Build status Go Report Card Coverage Status

A cross-platform game engine written in Go following an interpretation of the Entity Component System paradigm. Engo is currently compilable for Mac OSX, Linux and Windows. With the release of Go 1.4, supporting Android and the inception of iOS compatibility, mobile has been be added as a release target. Web support (wasm) is also available.

v1.0 is now available! To celebrate, there will be a game jam coming soon to celebrate the release, start actually building things and hopefully find any issues. Updates for this will come soon.

Getting in touch / Contributing

We have a gitter chat for people to join who want to further discuss engo. We are happy to discuss bugs, feature requests and would love to hear about the projects you are building!

Getting Started

Theory: common vs engo

There are currently two major important packages within this repository: github.com/EngoEngine/engo and github.com/EngoEngine/engo/common.

The top level engo package contains the functionality of creating windows, starting the game, creating an OpenGL context and handling input. It is designed to be used with Systems designed as per github.com/EngoEngine/ecs specifications. The common package contains our ECS implementations of common game development Systems like a RenderSystem or CameraSystem.

Practice: Getting it to Run
  1. First, you have to install some dependencies:
  2. If you're running on Debian/Ubuntu: sudo apt-get install libasound2-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev xorg-dev libgl1-mesa-dev git-all
  3. If you're running on Windows you'll need a gcc compiler that the go tool can use and have gcc.exe in your PATH environmental variable. We recommend Mingw since it has been tested. You'll also need git installed, we recommend getting it from The official Git site
  4. If you're on OSX, you will also need Git. You can find instructions here. You can also use homebrew to install git as well. Open an issue if you have any issues
  5. Then, you can go get it: go get -u github.com/EngoEngine/engo
  6. You may also want to get the dependencies of platform specific builds, so that build tools like godef can use them: go get -u -tags js ./... go get -u -tags android ./...
  7. Now, you have two choices:
  8. Visit our website, which hosts a full-blown tutorial series on how to create your own game, and on top of that, has some conceptual explanations;
  9. Check out some demos in our demos folder.
  10. Finally, if you run into problems, if you've encountered a bug, or want to request a feature, feel free to shoot us a DM or create an issue.

Breaking Changes Since v1.0

Engo is always undergoing a lot of optimizations and constantly gets new features. However, this sometimes means things break. In order to make transitioning easier for you, we have a list of those changes, with the most recent being at the top. If you run into any problems, please contact us at gitter.

  • TMXObject Width and Height is in pixels, and can be fractional. This has changed from an int to a float64.
  • TMXTileset now uses a Spritesheet instead of a Texture. This helps keep track of the guid better and allows the gid to not start at zero and have skips in it, as well as for borders and spacing in the tile sheet.
  • TMX Level's objects have all been rolled into Object rather than have separate things like "PolyLineObject". This is to be consistent with the TMX format.
  • The Shader interface now has a SetCamera(*CameraSystem) method. This method allows shaders to automatically update the camera system as it changes, such as between scenes or when the camera system is added.
  • The domain engo.io has expired. Now use github.com/EngoEngine/engo as the import path, and the site can be located at engoengine.github.io

Roadmap to v1.1

A list of issues for v1.1 can be found here. There's always room for improvement! Feel free to submit proposals, open issues, and let us know how we can improve!

History

Engo, originally known as Engi was written by ajhager as a general purpose Go game engine. With a desire to build it into an "ECS" game engine, it was forked to github.com/paked/engi. After passing through several iterations, it was decided that the project would be rebranded and rereleased as Engo on its own GitHub organization.

Credits

Thank you to everyone who has worked on, or with Engo. None of this would be possible without you, and your help has been truly amazing.

These are 3rd party projects that have made engo possible.

  • The original engi game engine which engo was based off of (BSD license)
  • Oto, a low-level cross-platform library to play sound. The AudioSystem uses this and is based on the audio package used in Ebiten.

Documentation

Index

Constants

View Source
const (
	// DefaultVerticalAxis is the name of the default vertical axis, as used internally in `engo` when `StandardInputs`
	// is defined.
	DefaultVerticalAxis = "vertical"

	// DefaultHorizontalAxis is the name of the default horizontal axis, as used internally in `engo` when `StandardInputs`
	// is defined.
	DefaultHorizontalAxis = "horizontal"
	// DefaultMouseXAxis is the name of the default horizontal mouse axis
	DefaultMouseXAxis = "mouse x"
	// DefaultMouseYAxis is the name of the default vertical mouse axis
	DefaultMouseYAxis = "mouse y"
)
View Source
const (
	// AxisMax is the maximum value a joystick or keypress axis will reach
	AxisMax float32 = 1
	// AxisNeutral is the value an axis returns if there has been to state change.
	AxisNeutral float32 = 0
	// AxisMin is the minimum value a joystick or keypress axis will reach
	AxisMin float32 = -1
)
View Source
const (
	// KeyStateUp is a state for when the key is not currently being pressed
	KeyStateUp = iota
	// KeyStateDown is a state for when the key is currently being pressed
	KeyStateDown
	// KeyStateJustDown is a state for when a key was just pressed
	KeyStateJustDown
	// KeyStateJustUp is a state for when a key was just released
	KeyStateJustUp
)
View Source
const (
	// Epsilon is some tiny value that determines how precisely equal we want our
	// floats to be.
	Epsilon float32 = 1e-3
	// MinNormal is the smallest normal value possible.
	MinNormal = float32(1.1754943508222875e-38) // 1 / 2**(127 - 1)

	// RadToDeg is multiplied with a radian value to get the equivalant value in degrees.
	RadToDeg = 180 / math.Pi
	// DegToRad is multiplied with a degree value to get the equivalent value in radians.
	DegToRad = math.Pi / 180
)

Variables

View Source
var (
	// Time is the active FPS counter
	Time *Clock

	// Input handles all input: mouse, keyboard and touch
	Input *InputManager

	// Mailbox is used by all Systems to communicate
	Mailbox *MessageManager

	// CurrentBackEnd is the current back end used for window management
	CurrentBackEnd BackEnd
	// ResizeXOffset is how far the screen moves from (0,0) being the top-left corner
	// when the window is resized
	ResizeXOffset = float32(0)
	// ResizeYOffset is how far the screen moves from (0,0) being the top-left corner
	// when the window is resized
	ResizeYOffset = float32(0)
)
View Source
var (
	// Window is the glfw.Window used for engo
	Window *glfw.Window
	// Gl is the current OpenGL context
	Gl *gl.Context
)
View Source
var (
	// Move is an action representing mouse movement
	Move = Action(0)
	// Press is an action representing a mouse press/click
	Press = Action(1)
	// Release is an action representing a mouse a release
	Release = Action(2)
	// Neutral represents a neutral action
	Neutral = Action(99)
	// Shift represents the shift modifier.
	// It is triggered when the shift key is pressed simultaneously with another key
	Shift = Modifier(0x0001)
	// Control represents the control modifier
	// It is triggered when the ctrl key is pressed simultaneously with another key
	Control = Modifier(0x0002)
	// Alt represents the alt modifier
	// It is triggered when the alt key is pressed simultaneously with another key
	Alt = Modifier(0x0004)
	// Super represents the super modifier
	// (Windows key on Microsoft Windows, Command key on Apple OSX, and varies on Linux)
	// It is triggered when the super key is pressed simultaneously with another key
	Super = Modifier(0x0008)
)
View Source
var Files = &Formats{formats: make(map[string]FileLoader)}

Files manages global resource handling of registered file formats for game assets.

Functions

func CanvasHeight

func CanvasHeight() float32

CanvasHeight gets the height of the current OpenGL Framebuffer

func CanvasScale

func CanvasScale() float32

CanvasScale gets the ratio of the canvas to the window sizes

func CanvasWidth

func CanvasWidth() float32

CanvasWidth gets the width of the current OpenGL Framebuffer

func CreateWindow

func CreateWindow(title string, width, height int, fullscreen bool, msaa int)

CreateWindow sets up the GLFW window and prepares the OpenGL surface for rendering

func CrossProduct

func CrossProduct(this, that Point) float32

CrossProduct returns the 2 dimensional cross product of this and that, which represents the magnitude of the three dimensional cross product

func CursorPos

func CursorPos() (x, y float32)

CursorPos returns the current cursor position

func DestroyWindow

func DestroyWindow()

DestroyWindow handles the termination of windows

func DotProduct

func DotProduct(this, that Point) float32

DotProduct returns the dot product between this and that

func Exit

func Exit()

Exit is the safest way to close your game, as `engo` will correctly attempt to close all windows, handlers and contexts

func FloatEqual

func FloatEqual(a, b float32) bool

FloatEqual is a safe utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

func FloatEqualThreshold

func FloatEqualThreshold(a, b, epsilon float32) bool

FloatEqualThreshold is a utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

This differs from FloatEqual in that it lets you pass in your comparison threshold, so that you can adjust the comparison value to your specific needs

func GameHeight

func GameHeight() float32

GameHeight returns the current game height

func GameWidth

func GameWidth() float32

GameWidth returns the current game width

func GetApplicationVersion added in v1.0.4

func GetApplicationVersion() [3]int

GetApplicationVersion returns the major, minor, and revision of the game.

func GetKeyName added in v1.0.5

func GetKeyName(k Key) string

GetKeyName returns the string returned from the given Key. So you can write "Press W to move forward" and get a W for QWERTY and Z for AZERTY

func GetTitle added in v1.0.4

func GetTitle() string

GetTitle returns the title of the game.

func Headless

func Headless() bool

Headless indicates whether or not OpenGL-calls should be made

func IsAndroidChrome

func IsAndroidChrome() bool

IsAndroidChrome tells if the browser is Chrome for android

func LineTraceFraction

func LineTraceFraction(tracer, boundary Line) float32

LineTraceFraction returns the trace fraction of tracer through boundary 1 means no intersection 0 means tracer's origin lies on the boundary line

func MultiplyMatrixVector added in v1.0.4

func MultiplyMatrixVector(m *Matrix, v []float32) []float32

MultiplyMatrixVector multiplies the matrix m with the float32 vector v and returns the result. The size of vector v MUST be 2 or 3. If v is size 2, a 3rd component is automatically added with value of 1.0.

func RegisterScene

func RegisterScene(s Scene)

RegisterScene registers the `Scene`, so it can later be used by `SetSceneByName`

func Run

func Run(o RunOptions, defaultScene Scene)

Run is called to create a window, initialize everything, and start the main loop. Once this function returns, the game window has been closed already. You can supply a lot of options within `RunOptions`, and your starting `Scene` should be defined in `defaultScene`.

func RunIteration

func RunIteration()

RunIteration runs one iteration per frame

func RunPreparation

func RunPreparation(defaultScene Scene)

RunPreparation is called automatically when calling Open. It should only be called once.

func ScaleOnResize

func ScaleOnResize() bool

ScaleOnResize indicates whether or not the screen should resize (i.e. make things look smaller/bigger) whenever the window resized. If `false`, then the size of the screen does not affect the size of the things drawn - it just makes less/more objects visible

func SetCursor

func SetCursor(c Cursor)

SetCursor sets the pointer of the mouse to the defined standard cursor

func SetCursorVisibility

func SetCursorVisibility(visible bool)

SetCursorVisibility sets the visibility of the cursor. If true the cursor is visible, if false the cursor is not.

func SetFPSLimit

func SetFPSLimit(limit int) error

SetFPSLimit can be used to change the value in the given `RunOpts` after already having called `engo.Run`.

func SetGlobalScale

func SetGlobalScale(p Point)

SetGlobalScale sets the GlobalScale to the given dimensions. If either dimension is less than or equal to zero, GlobalScale is set to (1, 1).

func SetOverrideCloseAction

func SetOverrideCloseAction(value bool)

SetOverrideCloseAction can be used to change the value in the given `RunOpts` after already having called `engo.Run`.

func SetScaleOnResize

func SetScaleOnResize(b bool)

SetScaleOnResize can be used to change the value in the given `RunOpts` after already having called `engo.Run`.

func SetScene

func SetScene(s Scene, forceNewWorld bool)

SetScene sets the currentScene to the given Scene, and optionally forcing to create a new ecs.World that goes with it.

func SetSceneByName

func SetSceneByName(name string, forceNewWorld bool) error

SetSceneByName does a lookup for the `Scene` where its `Type()` equals `name`, and then sets it as current `Scene`

func SetTitle

func SetTitle(title string)

SetTitle sets the title of the window

func SetVSync

func SetVSync(enabled bool)

SetVSync sets whether or not to use VSync

func WindowHeight

func WindowHeight() float32

WindowHeight gets the current window height

func WindowSize

func WindowSize() (w, h int)

WindowSize gets the current window size

func WindowWidth

func WindowWidth() float32

WindowWidth gets the current window width

Types

type AABB

type AABB struct {
	Min, Max Point
}

AABB describes two points of a rectangle: the upper-left corner and the lower-right corner. It should always hold that `Min.X <= Max.X` and `Min.Y <= Max.Y`.

type AABBer added in v1.0.4

type AABBer interface {
	// AABB returns the axis aligned bounding box.
	AABB() AABB
}

AABBer is an interface for everything that provides information about its axis aligned bounding box.

type Action

type Action int

Action corresponds to a control action such as move, press, release

type Axis

type Axis struct {
	// Name represents the name of the axis (Horizontal, Vertical)
	Name string
	// Pairs represents the axis pairs of this acis
	Pairs []AxisPair
}

An Axis is an input which is a spectrum of values. An example of this is the horizontal movement in a game, or how far a joystick is pressed.

func (Axis) Value

func (a Axis) Value() float32

Value returns the value of an Axis.

type AxisGamepad added in v1.0.6

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

func (*AxisGamepad) Value added in v1.0.6

func (ag *AxisGamepad) Value() float32

Value returns the amount and direction the axis is "tilted" from -1 to 1 0 being Neutral.

type AxisKeyPair

type AxisKeyPair struct {
	Min Key
	Max Key
}

An AxisKeyPair is a set of Min/Max values used for detecting whether or not a key has been pressed.

func (AxisKeyPair) Value

func (keys AxisKeyPair) Value() float32

Value returns the value of a keypress.

type AxisMouse

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

AxisMouse is an axis for a single x or y component of the Mouse. The value returned from it is the delta movement, since the previous call and it is not constrained by the AxisMin and AxisMax values.

func NewAxisMouse

func NewAxisMouse(d AxisMouseDirection) *AxisMouse

NewAxisMouse creates a new Mouse Axis in either direction AxisMouseVert or AxisMouseHori.

func (*AxisMouse) Value

func (am *AxisMouse) Value() float32

Value returns the delta of a mouse movement.

type AxisMouseDirection

type AxisMouseDirection uint

AxisMouseDirection is the direction (X or Y) which the mouse is being tracked for.

const (
	// AxisMouseVert is vertical mouse axis
	AxisMouseVert AxisMouseDirection = 0
	// AxisMouseHori is vertical mouse axis
	AxisMouseHori AxisMouseDirection = 1
)

type AxisPair

type AxisPair interface {
	Value() float32
}

An AxisPair is a set of Min/Max values which could possible be used by an Axis.

type BackEnd

type BackEnd uint

BackEnd represents the back end used for the window management / GL Surface

const (
	// BackEndGLFW uses glfw
	BackEndGLFW BackEnd = iota
	// BackEndWeb uses gopherjs
	BackEndWeb
	// BackEndMobile uses gomobile
	BackEndMobile
	// BackEndSDL uses sdl2
	BackEndSDL
	// BackEndHeadless does not use a window manager for the backend
	BackEndHeadless
	// BackEndVulkan uses glfw 3.3 from vulkan-go and vulkan as a render surface
	BackEndVulkan
)

type Button

type Button struct {
	Triggers []Key
	Name     string
}

A Button is an input which can be either JustPressed, JustReleased or Down. Common uses would be for, a jump key or an action key.

func (Button) Down

func (b Button) Down() bool

Down checks whether the current input is being held down.

func (Button) JustPressed

func (b Button) JustPressed() bool

JustPressed checks whether an input was pressed in the previous frame.

func (Button) JustReleased

func (b Button) JustReleased() bool

JustReleased checks whether an input was released in the previous frame.

type Clock

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

A Clock is a measurement built in `engo` to measure the actual frames per seconds (framerate).

func NewClock

func NewClock() *Clock

NewClock creates a new timer which allows you to measure ticks per seconds. Be sure to call `Tick()` whenever you want a tick to occur - it does not automatically tick each frame.

func (*Clock) Delta

func (c *Clock) Delta() float32

Delta is the amount of seconds between the last tick and the one before that

func (*Clock) FPS

func (c *Clock) FPS() float32

FPS is the amount of frames per second, computed every time a tick occurs at least a second after the previous update

func (*Clock) Pause added in v1.0.6

func (c *Clock) Pause()

Pause pauses the clock

func (*Clock) Tick

func (c *Clock) Tick()

Tick indicates a new tick/frame has occurred.

func (*Clock) Time

func (c *Clock) Time() float32

Time is the number of seconds the clock has been running

func (*Clock) Unpause added in v1.0.6

func (c *Clock) Unpause()

Unpause unpauses the clock

type Container

type Container interface {
	// Contains reports whether the container contains the given point.
	Contains(p Point) bool
}

A Container is a 2D closed shape which contains a set of points.

type Cursor

type Cursor uint8

Cursor is a reference to standard cursors, to be used in conjunction with `SetCursor`. What they look like, is different for each platform.

const (
	// CursorNone can be used to reset the cursor.
	CursorNone Cursor = iota
	// CursorArrow represents an arrow cursor
	CursorArrow
	// CursorCrosshair represents a crosshair cursor
	CursorCrosshair
	// CursorHand represents a hand cursor
	CursorHand
	// CursorIBeam represents an IBeam cursor
	CursorIBeam
	// CursorHResize represents a HResize cursor
	CursorHResize
	// CursorVResize represents a VResize cursor
	CursorVResize
)

type Exiter

type Exiter interface {
	// Exit is called when the user or the system requests to close the game
	// This should be used to cleanup or prompt user if they're sure they want to close
	// To prevent the default action (close/exit) make sure to set OverrideCloseAction in
	// your RunOpts to `true`. You should then handle the exiting of the program by calling
	//    engo.Exit()
	Exit()
}

Exiter is an optional interface a Scene can implement, indicating it'll have custom behavior whenever the game get closed.

type FileLoader

type FileLoader interface {
	// Load loads the given resource into memory.
	Load(url string, data io.Reader) error

	// Unload releases the given resource from memory.
	Unload(url string) error

	// Resource returns the given resource, and an error if it didn't succeed.
	Resource(url string) (Resource, error)
}

FileLoader implements support for loading and releasing file resources.

type FileLoaderRooter added in v1.0.6

type FileLoaderRooter interface {
	// SetRoot gives the root to the file loader. Generally before calling
	// the Load method
	SetRoot(root string)
}

FileLoaderRooter must be implemented by file loaders that need to known the root for their own functionning. This is generaly because they need to load other files that are referenced inside the first one and are relative to the first one, so their own call to open() need to be aware of the root dir or the load will fail. This is typically the case of a tmx loader that needs to load .tsx files that are given as urls inside the tmx

type Formats

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

Formats manages resource handling of registered file formats.

func (*Formats) GetRoot

func (formats *Formats) GetRoot() string

GetRoot returns the folder currently set at root.

func (*Formats) Load

func (formats *Formats) Load(urls ...string) error

Load loads the given resource(s) into memory, stopping at the first error.

func (*Formats) LoadReaderData

func (formats *Formats) LoadReaderData(url string, f io.Reader) error

LoadReaderData loads a resource when you already have the reader for it.

func (*Formats) Register

func (formats *Formats) Register(ext string, loader FileLoader)

Register registers a resource loader for the given file format.

func (*Formats) Resource

func (formats *Formats) Resource(url string) (Resource, error)

Resource returns the given resource, and an error if it didn't succeed.

func (*Formats) SetRoot

func (formats *Formats) SetRoot(root string)

SetRoot can be used to change the default directory from `assets` to whatever you want.

Whenever `root` does not start with the directory `assets`, you will not be able to support mobile (Android/iOS) since they require you to put all resources within the `assets` directory. More information about that is available here: https://godoc.org/golang.org/x/mobile/asset

You can, however, use subfolders within the `assets` folder, and set those as `root`.

func (*Formats) Unload

func (formats *Formats) Unload(url string) error

Unload releases the given resource from memory.

type Gamepad added in v1.0.6

type Gamepad struct {
	A, B, X, Y                            GamepadButton
	Back, Start, Guide                    GamepadButton
	DpadUp, DpadRight, DpadDown, DpadLeft GamepadButton
	LeftBumper, RightBumper               GamepadButton
	LeftThumb, RightThumb                 GamepadButton
	LeftX, LeftY                          AxisGamepad
	RightX, RightY                        AxisGamepad
	LeftTrigger, RightTrigger             AxisGamepad
	// contains filtered or unexported fields
}

Gampad is a configuration of a joystick that is able to be mapped to the SDL_GameControllerDB. For more info See https://www.glfw.org/docs/3.3/input_guide.html#gamepad_mapping

type GamepadButton added in v1.0.6

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

Gamepadbutton is a button on a Gamepad.

func (GamepadButton) Down added in v1.0.6

func (b GamepadButton) Down() bool

Down returns wether a key is being pressed

func (GamepadButton) JustPressed added in v1.0.6

func (b GamepadButton) JustPressed() bool

JustPressed returns whether a key was just pressed

func (GamepadButton) JustReleased added in v1.0.6

func (b GamepadButton) JustReleased() bool

JustReleased returns whether a key was just released

func (*GamepadButton) State added in v1.0.6

func (b *GamepadButton) State() int

State returns the raw state of a key.

func (GamepadButton) Up added in v1.0.6

func (b GamepadButton) Up() bool

Up returns wheter a key is not being pressed

type GamepadManager added in v1.0.6

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

GamepadManager manages the gamepads

func NewGamepadManager added in v1.0.6

func NewGamepadManager() *GamepadManager

NewGamepadManager creates a new GamepadManager

func (*GamepadManager) GetGamepad added in v1.0.6

func (gm *GamepadManager) GetGamepad(name string) *Gamepad

GetGamepad returns the gamepad previously registered with name.

func (*GamepadManager) Register added in v1.0.6

func (gm *GamepadManager) Register(name string) error

RegisterGamepad registers the gamepad with the given name. It can return an error if no suitable gamepads are located.

type HandlerIDPair

type HandlerIDPair struct {
	MessageHandlerId
	MessageHandler
}

type Hider

type Hider interface {
	// Hide is called when an other Scene becomes active
	Hide()
}

Hider is an optional interface a Scene can implement, indicating it'll have custom behavior whenever the Scene get hidden to make room fr other Scenes.

type InputManager

type InputManager struct {
	// Mouse is InputManager's reference to the mouse. It is recommended to use the
	// Axis and Button system if at all possible.
	Mouse Mouse
	// Modifier represents a special key pressed along with another key
	Modifier Modifier

	// Touches is the touches on the screen. There can be up to 5 recorded in Android,
	// and up to 4 on iOS. GLFW can also keep track of the touches. The latest touch is also
	// recorded in the Mouse so that touches readily work with the common.MouseSystem
	Touches map[int]Point
	// contains filtered or unexported fields
}

InputManager contains information about all forms of input.

func NewInputManager

func NewInputManager() *InputManager

NewInputManager holds onto anything input related for engo

func (*InputManager) Axis

func (im *InputManager) Axis(name string) Axis

Axis retrieves an Axis with a specified name.

func (*InputManager) Button

func (im *InputManager) Button(name string) Button

Button retrieves a Button with a specified name.

func (*InputManager) Gamepad added in v1.0.6

func (im *InputManager) Gamepad(name string) *Gamepad

Gamepad retrieves a Gamepad with a specified name.

func (*InputManager) RegisterAxis

func (im *InputManager) RegisterAxis(name string, pairs ...AxisPair)

RegisterAxis registers a new axis which can be used to retrieve inputs which are spectrums.

func (*InputManager) RegisterButton

func (im *InputManager) RegisterButton(name string, keys ...Key)

RegisterButton registers a new button input.

func (*InputManager) RegisterGamepad added in v1.0.6

func (im *InputManager) RegisterGamepad(name string) error

RegisterGamepad registers a new gamepad for use. It starts with joystick0 and continues until it finds one that can be used. If it does not find a suitable gamepad, an error will be returned.

type Key

type Key int

Key correspends to a keyboard key

const (
	// KeyGrave represents the '`' keyboard key
	KeyGrave Key = Key(glfw.KeyGraveAccent)
	// KeyDash represents the '-' keyboard key
	KeyDash Key = Key(glfw.KeyMinus)
	// KeyApostrophe represents the `'` keyboard key
	KeyApostrophe Key = Key(glfw.KeyApostrophe)
	// KeySemicolon represents the ';' keyboard key
	KeySemicolon Key = Key(glfw.KeySemicolon)
	// KeyEquals reprsents the '=' keyboard key
	KeyEquals Key = Key(glfw.KeyEqual)
	// KeyComma represents the ',' keyboard key
	KeyComma Key = Key(glfw.KeyComma)
	// KeyPeriod represents the '.' keyboard key
	KeyPeriod Key = Key(glfw.KeyPeriod)
	// KeySlash represents the '/' keyboard key
	KeySlash Key = Key(glfw.KeySlash)
	// KeyBackslash represents the '\' keyboard key
	KeyBackslash Key = Key(glfw.KeyBackslash)
	// KeyBackspace represents the backspace keyboard key
	KeyBackspace Key = Key(glfw.KeyBackspace)
	// KeyTab represents the tab keyboard key
	KeyTab Key = Key(glfw.KeyTab)
	// KeyCapsLock represents the caps lock keyboard key
	KeyCapsLock Key = Key(glfw.KeyCapsLock)
	// KeySpace represents the space keyboard key
	KeySpace Key = Key(glfw.KeySpace)
	// KeyEnter represents the enter keyboard key
	KeyEnter Key = Key(glfw.KeyEnter)
	// KeyEscape represents the escape keyboard key
	KeyEscape Key = Key(glfw.KeyEscape)
	// KeyInsert represents the insert keyboard key
	KeyInsert Key = Key(glfw.KeyInsert)
	// KeyPrintScreen represents the print screen keyboard key often
	// represented by 'Prt Scrn', 'Prt Scn', or 'Print Screen'
	KeyPrintScreen Key = Key(glfw.KeyPrintScreen)
	// KeyDelete represents the delete keyboard key
	KeyDelete Key = Key(glfw.KeyDelete)
	// KeyPageUp represents the page up keyboard key
	KeyPageUp Key = Key(glfw.KeyPageUp)
	// KeyPageDown represents the page down keyboard key
	KeyPageDown Key = Key(glfw.KeyPageDown)
	// KeyHome represents the home keyboard key
	KeyHome Key = Key(glfw.KeyHome)
	// KeyEnd represents the end keyboard key
	KeyEnd Key = Key(glfw.KeyEnd)
	// KeyPause represents the pause keyboard key
	KeyPause Key = Key(glfw.KeyPause)
	// KeyScrollLock represents the scroll lock keyboard key
	KeyScrollLock Key = Key(glfw.KeyScrollLock)
	// KeyArrowLeft represents the arrow left keyboard key
	KeyArrowLeft Key = Key(glfw.KeyLeft)
	// KeyArrowRight represents the arrow right keyboard key
	KeyArrowRight Key = Key(glfw.KeyRight)
	// KeyArrowDown represents the down arrow keyboard key
	KeyArrowDown Key = Key(glfw.KeyDown)
	// KeyArrowUp represents the up arrow keyboard key
	KeyArrowUp Key = Key(glfw.KeyUp)
	// KeyLeftBracket represents the '[' keyboard key
	KeyLeftBracket Key = Key(glfw.KeyLeftBracket)
	// KeyLeftShift represents the left shift keyboard key
	KeyLeftShift Key = Key(glfw.KeyLeftShift)
	// KeyLeftControl represents the left control keyboard key
	KeyLeftControl Key = Key(glfw.KeyLeftControl)
	// KeyLeftSuper represents the left super keyboard key
	// (Windows key on Microsoft Windows, Command key on Apple OSX, and varies on Linux)
	KeyLeftSuper Key = Key(glfw.KeyLeftSuper)
	// KeyLeftAlt represents the left alt keyboard key
	KeyLeftAlt Key = Key(glfw.KeyLeftAlt)
	// KeyRightBracket represents the ']' keyboard key
	KeyRightBracket Key = Key(glfw.KeyRightBracket)
	// KeyRightShift represents the right shift keyboard key
	KeyRightShift Key = Key(glfw.KeyRightShift)
	// KeyRightControl represents the right control keyboard key
	KeyRightControl Key = Key(glfw.KeyRightControl)
	// KeyRightSuper represents the right super keyboard key
	// (Windows key on Microsoft Windows, Command key on Apple OSX, and varies on Linux)
	KeyRightSuper Key = Key(glfw.KeyRightSuper)
	// KeyRightAlt represents the left alt keyboard key
	KeyRightAlt Key = Key(glfw.KeyRightAlt)
	// KeyZero represents the '0' keyboard key
	KeyZero Key = Key(glfw.Key0)
	// KeyOne represents the '1' keyboard key
	KeyOne Key = Key(glfw.Key1)
	// KeyTwo represents the '2' keyboard key
	KeyTwo Key = Key(glfw.Key2)
	// KeyThree represents the '3' keyboard key
	KeyThree Key = Key(glfw.Key3)
	// KeyFour represents the '4' keyboard key
	KeyFour Key = Key(glfw.Key4)
	// KeyFive represents the '5' keyboard key
	KeyFive Key = Key(glfw.Key5)
	// KeySix represents the '6' keyboard key
	KeySix Key = Key(glfw.Key6)
	// KeySeven represents the '7' keyboard key
	KeySeven Key = Key(glfw.Key7)
	// KeyEight represents the '8' keyboard key
	KeyEight Key = Key(glfw.Key8)
	// KeyNine represents the  '9' keyboard key
	KeyNine Key = Key(glfw.Key9)
	// KeyF1 represents the 'F1' keyboard key
	KeyF1 Key = Key(glfw.KeyF1)
	// KeyF2 represents the 'F2' keyboard key
	KeyF2 Key = Key(glfw.KeyF2)
	// KeyF3 represents the 'F3' keyboard key
	KeyF3 Key = Key(glfw.KeyF3)
	// KeyF4 represents the 'F4' keyboard key
	KeyF4 Key = Key(glfw.KeyF4)
	// KeyF5 represents the 'F5' keyboard key
	KeyF5 Key = Key(glfw.KeyF5)
	// KeyF6 represents the 'F6' keyboard key
	KeyF6 Key = Key(glfw.KeyF6)
	// KeyF7 represents the 'F7' keyboard key
	KeyF7 Key = Key(glfw.KeyF7)
	// KeyF8 represents the 'F8' keyboard key
	KeyF8 Key = Key(glfw.KeyF8)
	// KeyF9 represents the 'F9' keyboard key
	KeyF9 Key = Key(glfw.KeyF9)
	// KeyF10 represents the 'F10' keyboard key
	KeyF10 Key = Key(glfw.KeyF10)
	// KeyF11 represents the 'F11' keyboard key
	KeyF11 Key = Key(glfw.KeyF11)
	// KeyF12 represents the 'F12' keyboard key
	KeyF12 Key = Key(glfw.KeyF12)
	// KeyA represents the 'A' keyboard key
	KeyA Key = Key(glfw.KeyA)
	// KeyB represents the 'B' keyboard key
	KeyB Key = Key(glfw.KeyB)
	// KeyC represents the 'C' keyboard key
	KeyC Key = Key(glfw.KeyC)
	// KeyD represents the 'D' keyboard key '
	KeyD Key = Key(glfw.KeyD)
	// KeyE represents the 'E' keyboard key
	KeyE Key = Key(glfw.KeyE)
	// KeyF represents the 'F' keyboard key
	KeyF Key = Key(glfw.KeyF)
	// KeyG represents the 'G' keyboard key
	KeyG Key = Key(glfw.KeyG)
	// KeyH represents the 'H' keyboard key
	KeyH Key = Key(glfw.KeyH)
	// KeyI represents the 'I' keyboard key
	KeyI Key = Key(glfw.KeyI)
	// KeyJ represents the 'J' keyboard key
	KeyJ Key = Key(glfw.KeyJ)
	// KeyK represents the 'K' keyboard key
	KeyK Key = Key(glfw.KeyK)
	// KeyL represents the 'L' keyboard key
	KeyL Key = Key(glfw.KeyL)
	// KeyM represents the 'M' keyboard key
	KeyM Key = Key(glfw.KeyM)
	// KeyN represents the 'N' keyboard key
	KeyN Key = Key(glfw.KeyN)
	// KeyO represents the 'O' keyboard key
	KeyO Key = Key(glfw.KeyO)
	// KeyP represents the 'P' keyboard key
	KeyP Key = Key(glfw.KeyP)
	// KeyQ represents the 'Q' keyboard key
	KeyQ Key = Key(glfw.KeyQ)
	// KeyR represents the 'R' keyboard key
	KeyR Key = Key(glfw.KeyR)
	// KeyS represents the 'S' keyboard key
	KeyS Key = Key(glfw.KeyS)
	// KeyT represents the 'T' keyboard key
	KeyT Key = Key(glfw.KeyT)
	// KeyU represents the 'U' keyboard key
	KeyU Key = Key(glfw.KeyU)
	// KeyV represents the 'V' keyboard key
	KeyV Key = Key(glfw.KeyV)
	// KeyW represents the 'W' keyboard key
	KeyW Key = Key(glfw.KeyW)
	// KeyX represents the 'X' keyboard key
	KeyX Key = Key(glfw.KeyX)
	// KeyY represents the 'Y' keyboard key
	KeyY Key = Key(glfw.KeyY)
	// KeyZ represents the 'Z' keyboard key
	KeyZ Key = Key(glfw.KeyZ)
	// KeyNumLock represents the NumLock keyboard key on the numpad
	KeyNumLock Key = Key(glfw.KeyNumLock)
	// KeyNumMultiply represents the NumMultiply keyboard key on the numpad
	KeyNumMultiply Key = Key(glfw.KeyKPMultiply)
	// KeyNumDivide represents the NumDivide keyboard key on the numpad
	KeyNumDivide Key = Key(glfw.KeyKPDivide)
	// KeyNumAdd represents the NumAdd keyboard key on the numpad
	KeyNumAdd Key = Key(glfw.KeyKPAdd)
	// KeyNumSubtract represents the NumSubtract keyboard key on the numpad
	KeyNumSubtract Key = Key(glfw.KeyKPSubtract)
	// KeyNumZero represents the NumZero keyboard key on the numpad
	KeyNumZero Key = Key(glfw.KeyKP0)
	// KeyNumOne represents the NumOne keyboard key on the numpad
	KeyNumOne Key = Key(glfw.KeyKP1)
	// KeyNumTwo represents the NumTwo keyboard key on the numpad
	KeyNumTwo Key = Key(glfw.KeyKP2)
	// KeyNumThree represents the NumThree keyboard key on the numpad
	KeyNumThree Key = Key(glfw.KeyKP3)
	// KeyNumFour represents the NumFour keyboard key on the numpad
	KeyNumFour Key = Key(glfw.KeyKP4)
	// KeyNumFive represents the NumFive keyboard key on the numpad
	KeyNumFive Key = Key(glfw.KeyKP5)
	// KeyNumSix represents the NumSix keyboard key on the numpad
	KeyNumSix Key = Key(glfw.KeyKP6)
	// KeyNumSeven represents the NumSeven keyboard key on the numpad
	KeyNumSeven Key = Key(glfw.KeyKP7)
	// KeyNumEight represents the NumEight keyboard key on the numpad
	KeyNumEight Key = Key(glfw.KeyKP8)
	// KeyNumNine represents the NumNine keyboard key on the numpad
	KeyNumNine Key = Key(glfw.KeyKP9)
	// KeyNumDecimal represents the NumDecimal keyboard key on the numpad
	KeyNumDecimal Key = Key(glfw.KeyKPDecimal)
	// KeyNumEnter represents the NumEnter keyboard key on the numpad
	KeyNumEnter Key = Key(glfw.KeyKPEnter)
)

type KeyManager

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

KeyManager tracks which keys are pressed and released at the current point of time.

func NewKeyManager

func NewKeyManager() *KeyManager

NewKeyManager creates a new KeyManager.

func (*KeyManager) Get

func (km *KeyManager) Get(k Key) KeyState

Get retrieves a keys state.

func (*KeyManager) Set

func (km *KeyManager) Set(k Key, state bool)

Set is used for updating whether or not a key is held down, or not held down.

type KeyState

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

KeyState is used for detecting the state of a key press.

func (KeyState) Down

func (key KeyState) Down() bool

Down returns wether a key is being pressed

func (KeyState) JustPressed

func (key KeyState) JustPressed() bool

JustPressed returns whether a key was just pressed

func (KeyState) JustReleased

func (key KeyState) JustReleased() bool

JustReleased returns whether a key was just released

func (*KeyState) State

func (key *KeyState) State() int

State returns the raw state of a key.

func (KeyState) Up

func (key KeyState) Up() bool

Up returns wheter a key is not being pressed

type Line

type Line struct {
	P1 Point
	P2 Point
}

Line describes a line segment on a 2 dimensional euclidean space it can also be thought of as a 2 dimensional vector with an offset

func (*Line) Angle

func (l *Line) Angle() float32

Angle returns the euclidean angle of l in radians relative to a vertical line, going positive as you head towards the positive x-axis (clockwise) and negative as you head towards the negative x-axis. Values returned are [-pi, pi].

func (*Line) AngleDeg

func (l *Line) AngleDeg() float32

AngleDeg returns the euclidean angle of l in degrees relative to a vertical line, going positive as you head towards the positive x-axis (clockwise) and negative as you head towards the negative x-axis. Values returned are [-180, 180].

func (*Line) Magnitude added in v1.0.5

func (l *Line) Magnitude() float32

Magnitude returns the length of the line

func (*Line) Normal

func (l *Line) Normal() Point

Normal returns the left hand normal of the line segment l

func (*Line) PointDistance

func (l *Line) PointDistance(point Point) float32

PointDistance Returns the euclidean distance from the point p to the line segment l

func (*Line) PointDistanceSquared

func (l *Line) PointDistanceSquared(point Point) float32

PointDistanceSquared returns the squared euclidean distance from the point p to the line segment l

func (*Line) PointSide

func (l *Line) PointSide(point Point) bool

PointSide returns which side of the line l the point p sits on true means the point is below/left of the line false means the point is above/right of the line or touching the line

type Matrix added in v1.0.4

type Matrix struct {
	Val [9]float32
	// contains filtered or unexported fields
}

Matrix describes a 3x3 column-major matrix useful for 2D transformations.

func IdentityMatrix added in v1.0.4

func IdentityMatrix() *Matrix

IdentityMatrix returns a new identity matrix.

func (*Matrix) Identity added in v1.0.4

func (m *Matrix) Identity() *Matrix

Identity sets the matrix to the Identity matrix and returns the matrix.

func (*Matrix) Multiply added in v1.0.4

func (m *Matrix) Multiply(m2 *Matrix) *Matrix

Multiply postmultiplies m matrix with m2 and stores the result in m, returning m. Multiplaction is the result of m2 times m.

func (*Matrix) Rotate added in v1.0.4

func (m *Matrix) Rotate(deg float32) *Matrix

Rotate rorates m counter-clockwise by deg degrees.

func (*Matrix) RotateRad added in v1.0.4

func (m *Matrix) RotateRad(rad float32) *Matrix

RotateRad rotates m counter-clockwise by rad radians.

func (*Matrix) RotationComponent added in v1.0.4

func (m *Matrix) RotationComponent() float32

RotationComponent returns the current rotation component of m in degrees. This assumes uniform scaling.

func (*Matrix) RotationComponentRad added in v1.0.4

func (m *Matrix) RotationComponentRad() float32

RotationComponentRad returns the current rotation component of m in radians. This assumes uniform scaling.

func (*Matrix) Scale added in v1.0.4

func (m *Matrix) Scale(x, y float32) *Matrix

Scale scales m by x and y.

func (*Matrix) ScaleComponent added in v1.0.4

func (m *Matrix) ScaleComponent() (x, y float32)

ScaleComponent returns the current scale component of m. This assumes uniform scaling.

func (*Matrix) Set added in v1.0.4

func (m *Matrix) Set(val []float32) *Matrix

Set sets the matrix to the given float slice and returns the matrix. The float slice must have at least 9 elements. If the float slie contains more than 9 elements, only the first 9 will be copied.

func (*Matrix) Translate added in v1.0.4

func (m *Matrix) Translate(x, y float32) *Matrix

Translate translates m by the point (x, y).

func (*Matrix) TranslatePoint added in v1.0.4

func (m *Matrix) TranslatePoint(p Point) *Matrix

TranslatePoint translates m by the point p.

func (*Matrix) TranslationComponent added in v1.0.4

func (m *Matrix) TranslationComponent() (x, y float32)

TranslationComponent returns the current translation component of m. This assumes uniform scaling.

type Message

type Message interface {
	Type() string
}

A Message is used to send messages within the MessageManager

type MessageHandler

type MessageHandler func(msg Message)

A MessageHandler is used to dispatch a message to the subscribed handler.

type MessageHandlerId

type MessageHandlerId uint64

MessageHandlerId is used to track handlers, each handler will get a unique ID

type MessageManager

type MessageManager struct {
	// this mutex will prevent race
	// conditions on listeners and
	// sync its state across the game
	sync.RWMutex
	// contains filtered or unexported fields
}

MessageManager manages messages and subscribed handlers

func (*MessageManager) Dispatch

func (mm *MessageManager) Dispatch(message Message)

Dispatch sends a message to all subscribed handlers of the message's type To prevent any data races, be aware that these listeners occur as callbacks and can be executed at any time. If variables are altered in the handler, utilize channels, locks, semaphores, or any other method necessary to ensure the memory is not altered by multiple functions simultaneously.

func (*MessageManager) Listen

func (mm *MessageManager) Listen(messageType string, handler MessageHandler) MessageHandlerId

Listen subscribes to the specified message type and calls the specified handler when fired

func (*MessageManager) ListenOnce

func (mm *MessageManager) ListenOnce(messageType string, handler MessageHandler)

ListenOnce is a convenience wrapper around StopListen() to only listen to a specified message once

func (*MessageManager) StopListen

func (mm *MessageManager) StopListen(messageType string, handlerID MessageHandlerId)

StopListen removes a previously added handler from the listener queue

type Modifier

type Modifier int

Modifier represents a special key pressed along with another key

type Mouse

type Mouse struct {
	X, Y             float32
	ScrollX, ScrollY float32
	Action           Action
	Button           MouseButton
	Modifer          Modifier
}

Mouse represents the mouse

type MouseButton

type MouseButton int

MouseButton corresponds to a mouse button.

const (
	// MouseButtonLeft represents the left mouse button
	MouseButtonLeft MouseButton = 0
	// MouseButtonRight represents the right mouse button
	MouseButtonRight MouseButton = 1
	// MouseButtonMiddle represent the middle mosue button
	MouseButtonMiddle MouseButton = 2
	// MouseButton4 represents the 4th mouse button
	MouseButton4 MouseButton = 3
	// MouseButton5 represents the 5th mouse button
	MouseButton5 MouseButton = 4
	// MouseButton6 represents the 6th mouse button
	MouseButton6 MouseButton = 5
	// MouseButton7 represents the 7th mouse button
	MouseButton7 MouseButton = 6
	// MouseButton4 represents the last mouse button
	MouseButtonLast MouseButton = 7
)

Mouse buttons

type MouseState

type MouseState struct {
	// X and Y are the coordinates of the Mouse, relative to the `Canvas`.
	X, Y float32
	// ScrollX and ScrollY are the amount of scrolling the user has done with his mouse wheel in the respective directions.
	ScrollX, ScrollY float32
	// Action indicates what the gamer currently has done with his mouse.
	Action Action
	// Button indicates which button is being pressed by the gamer (if any).
	Button MouseButton
	// Modifier indicates which modifier (shift, alt, etc.) has been pressed during the Action.
	Modifier Modifier
}

MouseState represents the current state of the Mouse (or latest Touch-events).

type Point

type Point struct {
	X, Y float32
}

Point describes a coordinate in a 2 dimensional euclidean space it can also be thought of as a 2 dimensional vector from the origin

func GetGlobalScale

func GetGlobalScale() Point

GetGlobalScale returns the GlobalScale factor set in the RunOptions or via SetGlobalScale()

func LineIntersection

func LineIntersection(one, two Line) (Point, bool)

LineIntersection returns the point where the line segments one and two intersect and true if there is intersection, nil and false when line segments one and two do not intersect

func (*Point) Add

func (p *Point) Add(p2 Point) *Point

Add sets the components of p to the pointwise summation of p + p2

func (*Point) AddScalar

func (p *Point) AddScalar(s float32) *Point

AddScalar adds s to each component of p

func (*Point) Equal

func (p *Point) Equal(p2 Point) bool

Equal indicates whether two points have the same value, avoiding issues with float precision

func (*Point) Multiply

func (p *Point) Multiply(p2 Point) *Point

Multiply sets the components of p to the pointwise product of p * p2

func (*Point) MultiplyMatrixVector added in v1.0.4

func (p *Point) MultiplyMatrixVector(m *Matrix) *Point

MultiplyMatrixVector multiplies the matrix m with the point and returns the result.

func (*Point) MultiplyScalar

func (p *Point) MultiplyScalar(s float32) *Point

MultiplyScalar multiplies each component of p by s

func (*Point) Normalize

func (p *Point) Normalize() (Point, float32)

Normalize returns the unit vector from p, and its magnitude. if you try to normalize the null vector, the return value will be null values

func (*Point) PointDistance

func (p *Point) PointDistance(p2 Point) float32

PointDistance returns the euclidean distance between p and p2

func (*Point) PointDistanceSquared

func (p *Point) PointDistanceSquared(p2 Point) float32

PointDistanceSquared returns the squared euclidean distance between p and p2

func (*Point) ProjectOnto

func (p *Point) ProjectOnto(p2 Point) Point

ProjectOnto returns the vector produced by projecting p on to p2 returns an empty Point if they can't project onto one another

func (*Point) Set

func (p *Point) Set(x, y float32) *Point

Set sets the coordinates of p to x and y

func (*Point) Subtract

func (p *Point) Subtract(p2 Point) *Point

Subtract sets the components of p to the pointwise difference of p - p2

func (*Point) SubtractScalar

func (p *Point) SubtractScalar(s float32) *Point

SubtractScalar subtracts s from each component of p

func (Point) Within

func (p Point) Within(c Container) bool

Within reports whether the point is contained within the given container.

type Quadtree added in v1.0.4

type Quadtree struct {
	MaxObjects int // Maximum objects a node can hold before splitting into 4 subnodes
	MaxLevels  int // Total max levels inside root Quadtree

	Total int
	// contains filtered or unexported fields
}

Quadtree implementation which can store AABBer values

func NewQuadtree added in v1.0.4

func NewQuadtree(bounds AABB, usePool bool, maxObjects int) *Quadtree

NewQuadtree creates a new quadtree for the given bounds. When setting usePool to true, the internal values will be taken from a sync.Pool which reduces the allocation overhead. maxObjects tells the tree how many objects should be stored within a level before the quadtree cell is split.

func (*Quadtree) Clear added in v1.0.4

func (qt *Quadtree) Clear()

Clear removes all items from the quadtree

func (*Quadtree) Destroy added in v1.0.4

func (qt *Quadtree) Destroy()

Destroy frees the nodes if the Quadtree uses the node pool

func (*Quadtree) Insert added in v1.0.4

func (qt *Quadtree) Insert(item AABBer)

Insert inserts the given item to the quadtree

func (*Quadtree) Remove added in v1.0.4

func (qt *Quadtree) Remove(item AABBer)

Remove removes the given item from the quadtree

func (*Quadtree) Retrieve added in v1.0.4

func (qt *Quadtree) Retrieve(find AABB, filter func(aabb AABBer) bool) []AABBer

Retrieve returns all objects that could collide with the given bounding box and passing the given filter function.

type Resource

type Resource interface {
	// URL returns the uniform resource locator of the given resource.
	URL() string
}

Resource represents a game resource, such as an image or a sound.

type RunOptions

type RunOptions struct {
	// NoRun indicates the Open function should return immediately, without looping
	NoRun bool

	// Title is the Window title
	Title string

	// HeadlessMode indicates whether or not OpenGL calls should be made
	HeadlessMode bool

	// Fullscreen indicates the game should run in fullscreen mode if run on a desktop
	Fullscreen bool

	Width, Height int

	// GlobalScale scales all size/render components by the scale factor
	// Any point passed less than or equal to zero will result in the scale being set to
	// engo.Point{1, 1}.
	// All the systems in common should scale themselves accordingly (collision, camera, render, etc)
	// However, custom systems should be aware of this if this is set.
	GlobalScale Point

	// VSync indicates whether or not OpenGL should wait for the monitor to swp the buffers
	VSync bool

	// Resizable indicates whether or not the Window should be resizable.  Defaults to `false`.
	NotResizable bool

	// ScaleOnResize indicates whether or not engo should make things larger/smaller whenever the screen resizes
	ScaleOnResize bool

	// FPSLimit indicates the maximum number of frames per second
	FPSLimit int

	// OverrideCloseAction indicates that (when true) engo will never close whenever the gamer wants to close the
	// game - that will be your responsibility
	OverrideCloseAction bool

	// StandardInputs is an easy way to map common inputs to actions, such as "jump" being <SPACE>, and "action" being
	// <ENTER>.
	StandardInputs bool

	// MSAA indicates the amount of samples that should be taken. Leaving it blank will default to 1, and you may
	// use any positive value you wish. It may be possible that the operating system / environment doesn't support
	// the requested amount. In that case, GLFW will (hopefully) pick the highest supported sampling count. The higher
	// the value, the bigger the performance cost.
	//
	// Our `RenderSystem` automatically calls `gl.Enable(gl.MULTISAMPLE)` (which is required to make use of it), but
	// if you're going to use your own rendering `System` instead, you will have to call it yourself.
	//
	// Also note that this value is entirely ignored in WebGL - most browsers enable it by default when available, and
	// none of them (at time of writing) allow you to tune it.
	//
	// More info at https://www.opengl.org/wiki/Multisampling
	// "With multisampling, each pixel at the edge of a polygon is sampled multiple times."
	MSAA int

	// AssetsRoot is the path where all resources (images, audio files, fonts, etc.) can be found. Leaving this at
	// empty-string, will default this to `assets`.
	//
	// Whenever using any value that does not start with the directory `assets`, you will not be able to support
	// mobile (Android/iOS), because they **require** all assets to be within the `assets` directory. You may however
	// use any subfolder-structure within that `assets` directory.
	AssetsRoot string

	// MobileWidth and MobileHeight are the width and height given from the Android/iOS OpenGL Surface used for Gomobile bind
	MobileWidth, MobileHeight int

	// Update is the function called each frame during the runLoop to update all of the
	// systems. If left blank, it defaults to &ecs.World{}. Use this if you plan on utilizing
	// engo's window / GL management but don't want to use the ECS paradigm.
	Update Updater

	// ApplicationXXXVersion is the major, minor, and revision versions of the game.
	// defaults to 0.0.0
	ApplicationMajorVersion, ApplicationMinorVersion, ApplicationRevisionVersion int
}

RunOptions are the options used to Run engo

type Scene

type Scene interface {
	// Preload is called before loading resources
	Preload()

	// Setup is called before the main loop
	Setup(Updater)

	// Type returns a unique string representation of the Scene, used to identify it
	Type() string
}

Scene represents a screen ingame. i.e.: main menu, settings, but also the game itself

func CurrentScene

func CurrentScene() Scene

CurrentScene returns the SceneWorld that is currently active

type Shower

type Shower interface {
	// Show is called whenever the other Scene becomes inactive, and this one becomes the active one
	Show()
}

Shower is an optional interface a Scene can implement, indicating it'll have custom behavior whenever the Scene gets shown again after being hidden (due to switching to other Scenes)

type TextMessage added in v1.0.4

type TextMessage struct {
	Char rune
}

TextMessage is a message that is dispatched whenever a character is typed on the keyboard. This is not the same as a keypress, as it returns the rune of the character typed by the user, which could be a combination of keypresses.

func (TextMessage) Type added in v1.0.4

func (TextMessage) Type() string

Type returns the type of the message, "TextMessage"

type Trace

type Trace struct {
	Fraction    float32
	EndPosition Point
	Line
}

Trace describes all the values computed from a line trace

func LineTrace

func LineTrace(tracer Line, boundaries []Line) Trace

LineTrace runs a series of line traces from tracer to each boundary line and returns the nearest trace values

type Updater

type Updater interface {
	Update(float32)
}

Updater is an interface for what handles your game's Update during each frame. typically, this will be an *ecs.World, but you can implement your own Updater and use engo without using engo's ecs

type WindowResizeMessage

type WindowResizeMessage struct {
	OldWidth, OldHeight int
	NewWidth, NewHeight int
}

WindowResizeMessage is a message that's being dispatched whenever the game window is being resized by the gamer

func (WindowResizeMessage) Type

func (WindowResizeMessage) Type() string

Type returns the type of the current object "WindowResizeMessage"

Directories

Path Synopsis
Package common contains ECS implementations of commonly used game systems.
Package common contains ECS implementations of commonly used game systems.
internal/decode/convert
Package convert resamples and converts audio data
Package convert resamples and converts audio data
internal/decode/vorbis
Package vorbis provides Ogg/Vorbis decoder.
Package vorbis provides Ogg/Vorbis decoder.
internal/decode/wav
Package wav provides WAV (RIFF) decoder.
Package wav provides WAV (RIFF) decoder.
demos
assetbundling/assets
Code generated for package assets by go-bindata DO NOT EDIT.
Code generated for package assets by go-bindata DO NOT EDIT.
Package math currently is a wrapper to github.com/engoengine/math.
Package math currently is a wrapper to github.com/engoengine/math.

Jump to

Keyboard shortcuts

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