kamera

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: CC0-1.0 Imports: 3 Imported by: 0

README

kamera

kamera is a camera package for Ebitengine.

Example

Run example on your local machine

go run codeberg.org/setanarut/kamera/examples/topdown@latest
Key Action
WASD Move camera
E Zoom in
Q Zoom out
Space Reset camera
Key 1 look at the random object.
Key 2 Reset Zoom

Usage

Apply all world-space DrawImageOptions.GeoM transformations before Camera.Render(). Pay attention to the order, the order will affect the camera drawing.

A pseudo code:

func (g *Game) Update(screen *ebiten.Image) {
    g.MainCamera.LookAt(player.X, player.Y)
 }
func (g *Game) Draw(screen *ebiten.Image) {
    //  <- playerDrawImageOptions.GeoM world-space transformations will come here, or in Update()
    g.MainCamera.Render(player, playerDrawImageOptions, screen)
 }

See the ./examples/topdown/main.go for a real working code example.

Documentation

Overview

kamera is a camera package for ebitengine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	/* 	(X, Y) is the top left corner of the camera viewport.
	   	Use the `Camera.LookAt()` function to align the center of the camera to the target.
	   	(W, H) is the width and height of the camera viewport.
	   	it's recommended that the size is the same as the game and window size. */
	X, Y, W, H, Rotation, ZoomFactor float64
	// contains filtered or unexported fields
}

Camera object

func NewCamera

func NewCamera(w, h float64) *Camera

NewCamera returns new Camera

func (*Camera) LookAt

func (cam *Camera) LookAt(targetX, targetY float64)

LookAt aligns the midpoint of the camera viewport to the target.

func (*Camera) Render

func (cam *Camera) Render(worldObject *ebiten.Image, worldObjectOps *ebiten.DrawImageOptions, screen *ebiten.Image)

Render applies the Camera's geometric transformation then draws the object on the screen with drawing options.

func (*Camera) Reset

func (cam *Camera) Reset()

Reset resets all camera values to zero

func (*Camera) ScreenToWorld

func (cam *Camera) ScreenToWorld(screenX, screenY int) (worldX, worldY float64)

ScreenToWorld converts screen-space coordinates to world-space

func (*Camera) String

func (cam *Camera) String() string

String returns camera values as string

Directories

Path Synopsis
examples
topdown
| Key | Action | | ----- | -------------------------- | | WASD | Move camera | | E | Zoom in | | Q | Zoom out | | Space | Reset camera | | Key 1 | look at the random object.
| Key | Action | | ----- | -------------------------- | | WASD | Move camera | | E | Zoom in | | Q | Zoom out | | Space | Reset camera | | Key 1 | look at the random object.

Jump to

Keyboard shortcuts

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