ebiten

package module
v1.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

README

Ebiten (海老天)

Build Status

  • A simple SNES-like 2D game library in Go
  • Works on
    • Web browsers (powered by GopherJS)
      • Supported browsers: Chrome, Firefox, Safari on desktops
    • Mac OS X
    • Linux (maybe)
    • Windows (possibly)
  • API Docs

Features

  • 2D Graphics
  • Input (Mouse, Keyboard)

Documentation

http://hajimehoshi.github.io/ebiten/

License

Ebiten is licensed under Apache license version 2.0. See license.txt.

Documentation

Overview

Package ebiten provides graphics and input API to develop a 2D game.

You can start the game by calling the function Run.

func update(screen *ebiten.Screen) {
    // Define your game.
}

func main() {
    ebiten.Run(update, 320, 240, 2, "Your game's title")
}

Index

Constants

View Source
const (
	Key0         = Key(ui.Key0)
	Key1         = Key(ui.Key1)
	Key2         = Key(ui.Key2)
	Key3         = Key(ui.Key3)
	Key4         = Key(ui.Key4)
	Key5         = Key(ui.Key5)
	Key6         = Key(ui.Key6)
	Key7         = Key(ui.Key7)
	Key8         = Key(ui.Key8)
	Key9         = Key(ui.Key9)
	KeyA         = Key(ui.KeyA)
	KeyB         = Key(ui.KeyB)
	KeyC         = Key(ui.KeyC)
	KeyD         = Key(ui.KeyD)
	KeyE         = Key(ui.KeyE)
	KeyF         = Key(ui.KeyF)
	KeyG         = Key(ui.KeyG)
	KeyH         = Key(ui.KeyH)
	KeyI         = Key(ui.KeyI)
	KeyJ         = Key(ui.KeyJ)
	KeyK         = Key(ui.KeyK)
	KeyL         = Key(ui.KeyL)
	KeyM         = Key(ui.KeyM)
	KeyN         = Key(ui.KeyN)
	KeyO         = Key(ui.KeyO)
	KeyP         = Key(ui.KeyP)
	KeyQ         = Key(ui.KeyQ)
	KeyR         = Key(ui.KeyR)
	KeyS         = Key(ui.KeyS)
	KeyT         = Key(ui.KeyT)
	KeyU         = Key(ui.KeyU)
	KeyV         = Key(ui.KeyV)
	KeyW         = Key(ui.KeyW)
	KeyX         = Key(ui.KeyX)
	KeyY         = Key(ui.KeyY)
	KeyZ         = Key(ui.KeyZ)
	KeyAlt       = Key(ui.KeyAlt)
	KeyBackspace = Key(ui.KeyBackspace)
	KeyCapsLock  = Key(ui.KeyCapsLock)
	KeyComma     = Key(ui.KeyComma)
	KeyControl   = Key(ui.KeyControl)
	KeyDelete    = Key(ui.KeyDelete)
	KeyDown      = Key(ui.KeyDown)
	KeyEnd       = Key(ui.KeyEnd)
	KeyEnter     = Key(ui.KeyEnter)
	KeyEscape    = Key(ui.KeyEscape)
	KeyF1        = Key(ui.KeyF1)
	KeyF2        = Key(ui.KeyF2)
	KeyF3        = Key(ui.KeyF3)
	KeyF4        = Key(ui.KeyF4)
	KeyF5        = Key(ui.KeyF5)
	KeyF6        = Key(ui.KeyF6)
	KeyF7        = Key(ui.KeyF7)
	KeyF8        = Key(ui.KeyF8)
	KeyF9        = Key(ui.KeyF9)
	KeyF10       = Key(ui.KeyF10)
	KeyF11       = Key(ui.KeyF11)
	KeyF12       = Key(ui.KeyF12)
	KeyHome      = Key(ui.KeyHome)
	KeyInsert    = Key(ui.KeyInsert)
	KeyLeft      = Key(ui.KeyLeft)
	KeyPageDown  = Key(ui.KeyPageDown)
	KeyPageUp    = Key(ui.KeyPageUp)
	KeyPeriod    = Key(ui.KeyPeriod)
	KeyRight     = Key(ui.KeyRight)
	KeyShift     = Key(ui.KeyShift)
	KeySpace     = Key(ui.KeySpace)
	KeyTab       = Key(ui.KeyTab)
	KeyUp        = Key(ui.KeyUp)
)

Keys

View Source
const (
	MouseButtonLeft   = MouseButton(ui.MouseButtonLeft)
	MouseButtonRight  = MouseButton(ui.MouseButtonRight)
	MouseButtonMiddle = MouseButton(ui.MouseButtonMiddle)
)

MouseButtons

View Source
const ColorMDim = 5

ColorMDim is a dimension of a ColorM.

View Source
const GeoMDim = 3

GeoMDim is a dimension of a GeoM.

Variables

This section is empty.

Functions

func CursorPosition

func CursorPosition() (x, y int)

CursorPosition returns a position of a mouse cursor.

func IsKeyPressed

func IsKeyPressed(key Key) bool

IsKeyPressed returns a boolean indicating whether key is pressed.

func IsMouseButtonPressed

func IsMouseButtonPressed(mouseButton MouseButton) bool

IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.

func Run

func Run(f func(*Image) error, width, height, scale int, title string) error

Run runs the game. f is a function which is called at every frame. The argument (*Image) is the render target that represents the screen.

This function must be called from the main thread.

The given function f is expected to be called 60 times a second, but this is not strictly guaranteed. If you need to care about time, you need to check current time every time f is called.

Types

type ColorM

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

A ColorM represents a matrix to transform coloring when rendering an image.

A ColorM is applied to the source alpha color while an Image's pixels' format is alpha premultiplied. Before applying a matrix, a color is un-multiplied, and after applying the matrix, the color is multiplied again.

The initial value is identity.

func Monochrome

func Monochrome() ColorM

Monochrome returns a color matrix to make an image monochrome.

func RotateHue

func RotateHue(theta float64) ColorM

RotateHue returns a color matrix to rotate the hue

func ScaleColor

func ScaleColor(r, g, b, a float64) ColorM

ScaleColor returns a color matrix that scales a color matrix by the given color (r, g, b, a).

func TranslateColor

func TranslateColor(r, g, b, a float64) ColorM

TranslateColor returns a color matrix that translates a color matrix by the given color (r, g, b, a).

func (*ColorM) Add

func (c *ColorM) Add(other ColorM)

Add adds a color matrix with the other color matrix.

func (*ColorM) Concat

func (c *ColorM) Concat(other ColorM)

Concat multiplies a color matrix with the other color matrix.

func (*ColorM) Element

func (c *ColorM) Element(i, j int) float64

Element returns a value of a matrix at (i, j).

func (*ColorM) Scale added in v1.1.0

func (c *ColorM) Scale(r, g, b, a float64)

func (*ColorM) SetElement

func (c *ColorM) SetElement(i, j int, element float64)

SetElement sets an element at (i, j).

func (*ColorM) Translate added in v1.1.0

func (c *ColorM) Translate(r, g, b, a float64)

type DrawImageOptions

type DrawImageOptions struct {
	ImageParts ImageParts
	GeoM       GeoM
	ColorM     ColorM

	// Deprecated (as of 1.1.0-alpha): Use ImageParts instead.
	Parts []ImagePart
}

A DrawImageOptions represents options to render an image on an image.

type Filter

type Filter int

Filter represents the type of filter to be used when an image is maginified or minified.

const (
	FilterNearest Filter = iota
	FilterLinear
)

Filters

type GeoM

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

A GeoM represents a matrix to transform geometry when rendering an image.

The initial value is identity.

func RotateGeo

func RotateGeo(theta float64) GeoM

RotateGeo returns a matrix that rotates a geometry matrix by theta.

func ScaleGeo

func ScaleGeo(x, y float64) GeoM

ScaleGeo returns a matrix that scales a geometry matrix by (x, y).

func TranslateGeo

func TranslateGeo(tx, ty float64) GeoM

TranslateGeo returns a matrix taht translates a geometry matrix by (tx, ty).

func (*GeoM) Add

func (g *GeoM) Add(other GeoM)

Add adds a geometry matrix with the other geometry matrix.

func (*GeoM) Concat

func (g *GeoM) Concat(other GeoM)

Concat multiplies a geometry matrix with the other geometry matrix.

func (*GeoM) Element

func (g *GeoM) Element(i, j int) float64

Element returns a value of a matrix at (i, j).

func (*GeoM) Rotate added in v1.1.0

func (g *GeoM) Rotate(theta float64)

func (*GeoM) Scale added in v1.1.0

func (g *GeoM) Scale(x, y float64)

func (*GeoM) SetElement

func (g *GeoM) SetElement(i, j int, element float64)

SetElement sets an element at (i, j).

func (*GeoM) Translate added in v1.1.0

func (g *GeoM) Translate(tx, ty float64)

type Image

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

Image represents an image. The pixel format is alpha-premultiplied. Image implements image.Image.

func NewImage

func NewImage(width, height int, filter Filter) (*Image, error)

NewImage returns an empty image.

func NewImageFromImage

func NewImageFromImage(img image.Image, filter Filter) (*Image, error)

NewImageFromImage creates a new image with the given image (img).

func (*Image) At

func (i *Image) At(x, y int) color.Color

At returns the color of the image at (x, y).

This method loads pixels from GPU to VRAM if necessary.

func (*Image) Bounds

func (i *Image) Bounds() image.Rectangle

Bounds returns the bounds of the image.

func (*Image) Clear

func (i *Image) Clear() (err error)

Clear resets the pixels of the image into 0.

func (*Image) ColorModel

func (i *Image) ColorModel() color.Model

ColorModel returns the color model of the image.

func (*Image) DrawImage

func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error)

DrawImage draws the given image on the receiver image.

This method accepts the options. The parts of the given image at the parts of the destination. After determining parts to draw, this applies the geometry matrix and the color matrix.

Here are the default values:

ImageParts: (0, 0) - (source width, source height) to (0, 0) - (source width, source height)
            (i.e. the whole source image)
GeoM:       Identity matrix
ColorM:     Identity matrix (that changes no colors)

Be careful that this method is potentially slow. It would be better if you could call this method fewer times.

func (*Image) Fill

func (i *Image) Fill(clr color.Color) (err error)

Fill fills the image with a solid color.

func (*Image) Size

func (i *Image) Size() (width, height int)

Size returns the size of the image.

type ImagePart

type ImagePart struct {
	Dst image.Rectangle
	Src image.Rectangle
}

Deprecated (as of 1.1.0-alpha): Use ImageParts instead.

type ImageParts added in v1.1.0

type ImageParts interface {
	Len() int
	Dst(i int) (x0, y0, x1, y1 int)
	Src(i int) (x0, y0, x1, y1 int)
}

An ImageParts represents the parts of the destination image and the parts of the source image.

type Key

type Key int

A Key represents a keyboard key.

type MouseButton

type MouseButton int

A MouseButton represents a mouse button.

Jump to

Keyboard shortcuts

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