ebiten

package module
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2014 License: Apache-2.0 Imports: 10 Imported by: 0

README

Ebiten (海老天)

Build Status

  • A simple SNES-like 2D game library in Go
  • Works on
    • Mac OS X
    • Linux (maybe)
    • Windows (possibly)
  • API Docs

Features

  • 2D Graphics
  • Input (Mouse, Keyboard)

Example

  • example/blocks - Puzzle game you know
  • example/hue - Changes the hue of an image
  • example/mosaic - Mosaics an image
  • example/perspective - See an image in a perspective view
  • example/rotate - Rotates an image
  • etc.

Install on Mac OS X

:; brew install glew
:; brew install glfw3 # or homebrew/versions/glfw3
:; go get -u github.com/hajimehoshi/ebiten

Execute the example

:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
:; go run rotate/main.go
Benchmark the example
:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
:; go build -o=example blocks/main.go
:; ./example -cpuprofile=cpu.out
:; go tool pprof ./example cpu.out

Versioning

License

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 (
	FilterNearest = Filter(opengl.FilterNearest)
	FilterLinear  = Filter(opengl.FilterLinear)
)

Filters

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) SetElement

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

SetElement sets an element at (i, j).

type DrawImageOptions

type DrawImageOptions struct {
	Parts  []ImagePart
	GeoM   GeoM
	ColorM ColorM
}

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

type Filter

type Filter opengl.Filter

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

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) SetElement

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

SetElement sets an element at (i, j).

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:

Parts:  (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)

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
}

type Key

type Key int

A Key represents a keyboard key.

const (
	KeyUp Key = iota
	KeyDown
	KeyLeft
	KeyRight
	KeySpace
	KeyMax
)

Keys

type MouseButton

type MouseButton int

A MouseButton represents a mouse button.

const (
	MouseButtonLeft MouseButton = iota
	MouseButtonRight
	MouseButtonMiddle
	MouseButtonMax
)

MouseButtons

Jump to

Keyboard shortcuts

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