Aego Русский

aego/camera

Virtual cameras are components; this package switches between them and adds shake. Shake grows with trauma, which fades over time and is scaled by the accessibility setting. In the documentation sandbox nothing is drawn; the example logs how trauma fades. See Cameras 2D.

On this page

Example

package demo

import (
    "aego/camera"
    "aego/log"
)

script Quake {
    @export var Strength float = 0.6

    var frames int

    func Ready() {
        camera.Shake(Strength)
        log.Info("trauma " + string(camera.Trauma()))
    }

    func Update(dt float) {
        frames++
        if frames % 20 == 0 {
            log.Info("trauma " + string(camera.Trauma()))
        }
        if frames == 60 {
            camera.Shake(0.3)
            log.Info("shaken again, trauma " + string(camera.Trauma()))
        }
    }
}

Functions

Active() NodeRefReturns the virtual camera that drives the main output, or nil.
ActiveOn(output string) NodeRefReturns the virtual camera that drives the named output.
BlendBlend is a running blend between virtual cameras. yield b waits until it ends; a nil blend is done.
BlendTo(camera NodeRef, seconds float) Handle<aego/camera.Blend>Makes vc active over priorities and blends to it; seconds 0 uses its Blend Time. Release hands control back to priorities.
Cut(camera NodeRef)Makes vc active at once, without a blend.
LogicalPose() aego/camera.PoseReturns the pose of the main output without shake and pixel snapping.
PosePose is a camera position in world units, a rotation in radians and a zoom in pixels per unit.
Release(seconds float) Handle<aego/camera.Blend>Ends BlendTo or Cut on the main output; priorities decide again, blending over seconds or the camera's Blend Time.
RenderPose() aego/camera.PoseReturns the pose the main output was drawn with in the last frame.
ScreenToWorld(point Vec2) Vec2Converts output pixels to world units with the last drawn view of the main output.
Shake(trauma float)Adds trauma to the main output; shake grows with trauma, which is capped at 1 and fades over time.
ShakeOn(output string, trauma float)Adds trauma to the named output.
Trauma() floatReturns the current trauma of the main output, 0 to 1.
WorldToScreen(point Vec2) Vec2Converts world units to output pixels with the last drawn view of the main output.

Active function

func Active() NodeRef

Returns the virtual camera that drives the main output, or nil.

See the module example for this function in use.

ActiveOn function

func ActiveOn(output string) NodeRef

Returns the virtual camera that drives the named output.

See the module example for this function in use.

BlendTo function

func BlendTo(camera NodeRef, seconds float) Handle<aego/camera.Blend>

Makes vc active over priorities and blends to it; seconds 0 uses its Blend Time. Release hands control back to priorities.

Example

yield camera.BlendTo(BossCam, 1.5)

Cut function

func Cut(camera NodeRef)

Makes vc active at once, without a blend.

See the module example for this function in use.

LogicalPose function

func LogicalPose() aego/camera.Pose

Returns the pose of the main output without shake and pixel snapping.

See the module example for this function in use.

Release function

func Release(seconds float) Handle<aego/camera.Blend>

Ends BlendTo or Cut on the main output; priorities decide again, blending over seconds or the camera's Blend Time.

See the module example for this function in use.

RenderPose function

func RenderPose() aego/camera.Pose

Returns the pose the main output was drawn with in the last frame.

See the module example for this function in use.

ScreenToWorld function

func ScreenToWorld(point Vec2) Vec2

Converts output pixels to world units with the last drawn view of the main output.

See the module example for this function in use.

Shake function

func Shake(trauma float)

Adds trauma to the main output; shake grows with trauma, which is capped at 1 and fades over time.

Example

camera.Shake(0.4)

ShakeOn function

func ShakeOn(output string, trauma float)

Adds trauma to the named output.

See the module example for this function in use.

Trauma function

func Trauma() float

Returns the current trauma of the main output, 0 to 1.

See the module example for this function in use.

WorldToScreen function

func WorldToScreen(point Vec2) Vec2

Converts world units to output pixels with the last drawn view of the main output.

See the module example for this function in use.