lense

package module
v0.0.0-...-d2b244f Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: MIT Imports: 3 Imported by: 0

README

lense

A camera system for amore

Example

package main

import (
  "github.com/tanema/amore"
  "github.com/tanema/amore/gfx"
  "github.com/tanema/amore/keyboard"
  "github.com/tanema/lense"
)

var (
  camera *lense.Camera
)

func main() {
  amore.Start(update, draw)
}

func update(dt float32) {
  if keyboard.IsDown(keyboard.KeyLeft) {
    camera.Move(-1, 0)
  } else if keyboard.IsDown(keyboard.KeyRight) {
    camera.Move(1, 0)
  }

  if keyboard.IsDown(keyboard.KeyUp) {
    camera.Move(0, -1)
  } else if keyboard.IsDown(keyboard.KeyDown) {
    camera.Move(0, 1)
  }

  if keyboard.IsDown(keyboard.KeyS) {
    camera.Shake(2)
  }

  camera.Update(dt)
}

func draw() {
  camera.Draw(func(l, t, w, h float32){
    gfx.Rect(gfx.FILL, 200, 200, 200, 200)
  })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

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

Camera is the main object to handle all camera operations

func New

func New() *Camera

New will return a new Camera object for the current screen extents

func (*Camera) Draw

func (camera *Camera) Draw(draw func(l, t, w, h float32))

Draw is the function to scope all your draw calls to be transformed to the camera veiw. Pass in a function that takes the extents of the camera to be called for drawing the scene within the camera view.

func (*Camera) GetVisible

func (camera *Camera) GetVisible() (l, t, w, h float32)

GetVisible returns the extents of the visible area that the camera can see. The top left x, y and the width and height of the frame.

func (*Camera) LookAt

func (camera *Camera) LookAt(x, y float32)

LookAt will set the camera to looking at the provided x, y coords.

func (*Camera) Move

func (camera *Camera) Move(dx, dy float32)

Move will move the camera by the difference of x or y

func (*Camera) Rotate

func (camera *Camera) Rotate(phi float32)

Rotate will rotate the view of the camera around the center coords that the camera is looking at

func (*Camera) RotateTo

func (camera *Camera) RotateTo(phi float32)

RotateTo will set the camera rotation to the radian provided

func (*Camera) Shake

func (camera *Camera) Shake(intensity float32)

Shake will cause the camera to jump around making it seem like the whole view is shaking. If you want to use this function then you will need to call Update in your global update function.

func (*Camera) Update

func (camera *Camera) Update(dt float32)

Update will update the shake functionality. This method is only needed if Shake is used.

func (*Camera) Zoom

func (camera *Camera) Zoom(mul float32)

Zoom will scale the scene by the multiplyer provided. for instance if 2 is provided then everything is scaled to twice the size.

func (*Camera) ZoomTo

func (camera *Camera) ZoomTo(zoom float32)

ZoomTo will set the scale factor. If 1 is passed then the zoom will be default

Jump to

Keyboard shortcuts

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