viewlib

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 2 Imported by: 0

README

viewlib

A small library for Ebitengine for layered rendering and includes a basic camera implementation modified from ebiten-camera.

Layered rendering

var (
	cam *viewlib.Camera
)

func main() {
	ebiten.SetWindowSize(1366, 768)
	ebiten.SetWindowTitle("viewlib")

	if err := ebiten.RunGame(&Game{}); err != nil {
		log.Fatal(err)
	}
}

type Game struct {
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
	return outsideWidth, outsideHeight
}

func (g *Game) Update() error {

	return nil
}

func (g *Game) LayerRender(screen *ebiten.Image) {
	layer := 1
    viewlib.Draw(image.Image, viewlib.RenderModeWorld, layer).
        Position(100, 100).
        Rotation(float32(22.0)).
        Queue()
}

func (g *Game) Draw(screen *ebiten.Image) {
	viewlib.RenderTo(screen, cam)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QueueFunc added in v0.0.4

func QueueFunc(renderFunc func(screen *ebiten.Image, camera *Camera), layer int)

QueueFunc is used to queue an arbitrary screen aware function to run.

func QueueRender added in v0.0.4

func QueueRender(op *DrawOp, mode RenderMode, layer int)

QueueRender adds a draw operation to the render queue. The `mode` argument specifies whether the draw operation is executed on the world space layer or the canvas layer.

func RenderTo added in v0.0.4

func RenderTo(screen *ebiten.Image, camera *Camera)

RenderTo should be called by your render loop, and will draw all queued operations to the screen. It will clear the screen, and clear the queue.

Types

type Camera

type Camera struct {
	X, Y, Scale   float64
	Width, Height int
}

Camera can look at positions, zoom and rotate. The Camera implementation is a modified https://github.com/MelonFunction/ebiten-camera.

func NewCamera

func NewCamera(width, height int, x, y, zoom float64) *Camera

NewCamera returns a new Camera.

func (*Camera) Center

func (c *Camera) Center() (float64, float64)

Center returns the center point of the camera, based on its Width and Height.

func (*Camera) GetCursorCoords

func (c *Camera) GetCursorCoords() (float64, float64)

GetCursorCoords converts cursor/screen coords into world coords

func (*Camera) GetScreenCoords

func (c *Camera) GetScreenCoords(x, y float64) (float64, float64)

GetScreenCoords converts world coords into screen coords

func (*Camera) GetWorldCoords

func (c *Camera) GetWorldCoords(x, y float64) (float64, float64)

GetWorldCoords converts screen coords into world coords

func (*Camera) MovePosition

func (c *Camera) MovePosition(x, y float64) *Camera

MovePosition moves the Camera by x and y. Use SetPosition if you want to set the position

func (*Camera) Resize

func (c *Camera) Resize(w, h int) *Camera

Resize resizes the camera Surface

func (*Camera) SetPosition

func (c *Camera) SetPosition(x, y float64) *Camera

SetPosition looks at a position

func (*Camera) SetZoom

func (c *Camera) SetZoom(zoom float64) *Camera

SetZoom sets the zoom

func (*Camera) WorldMatrix

func (c *Camera) WorldMatrix(ops *ebiten.DrawImageOptions)

WorldMatrix modifies the `ops` parameter to be world relative.

func (*Camera) Zoom

func (c *Camera) Zoom(mul float64) *Camera

Zoom *= the current zoom

type DrawOp

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

func Draw

func Draw(image *ebiten.Image, mode RenderMode, layer int) *DrawOp

Draw returns a new DrawOp which can be used to customize how the image is rendered. By using Draw instead of manual ebiten drawing, you get automatic handling of rotations and sprite origins. DrawOp makes sure the draw operations are performed in the correct order. Call QueueRender() to draw onto the render pass.

func (*DrawOp) CenterOrigin

func (d *DrawOp) CenterOrigin() *DrawOp

CenterOrigin sets the origin of the sprite to its center.

func (*DrawOp) Filter

func (d *DrawOp) Filter(filter ebiten.Filter) *DrawOp

Filter sets the draw filter mode.

func (*DrawOp) Mode added in v0.0.4

func (d *DrawOp) Mode(mode RenderMode) *DrawOp

func (*DrawOp) Origin

func (d *DrawOp) Origin(originX, originY float64) *DrawOp

Origin sets the origin of the sprite.

func (*DrawOp) Position

func (d *DrawOp) Position(posX, posY float64) *DrawOp

Position sets the position of the sprite.

func (*DrawOp) Queue added in v0.0.4

func (d *DrawOp) Queue()

Queue adds the draw op to the rendering queue.

func (*DrawOp) Rotation

func (d *DrawOp) Rotation(rotation float32) *DrawOp

Rotation sets the rotation of the sprite.

func (*DrawOp) Scale

func (d *DrawOp) Scale(scale float64) *DrawOp

Scale sets the scale of the sprite.

func (*DrawOp) Skew

func (d *DrawOp) Skew(skewX, skewY float64) *DrawOp

Skew sets the skew of the sprite.

type RenderMode added in v0.0.4

type RenderMode uint

RenderMode represents the type of rendering that will be done. RenderModeCanvas is used for screen space rendering. RenderModeWorld is used for world space rendering.

const (
	RenderModeCanvas RenderMode = iota + 1
	RenderModeWorld
)

Jump to

Keyboard shortcuts

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