Documentation ¶
Overview ¶
Package scene provides definitions for interacting with game loop scenes.
Index ¶
- func BooleanLoop(b *bool) func() (cont bool)
- func Fade(rate float32, frames int) func(*image.RGBA, int) bool
- func GoTo(nextScene string) func() (nextScene string, result *Result)
- func GoToPtr(nextScene *string) func() (nextScene string, result *Result)
- func Zoom(xPerc, yPerc float64, frames int, zoomRate float64) func(*image.RGBA, int) bool
- type Context
- type Map
- type Result
- type Scene
- type Transition
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BooleanLoop ¶
BooleanLoop returns a Loop function that will end a scene as soon as the input boolean is false, resetting it to true in the process for the next scene
func Fade ¶
Fade is a scene transition that fades to black at a given rate for a total of 'frames' frames
func GoTo ¶
GoTo returns an End function that, without any other customization possible, will change to the input next scene.
Types ¶
type Context ¶
type Context struct { // This context will be canceled when the scene ends context.Context PreviousScene string SceneInput interface{} Window window.Window DrawStack *render.DrawStack EventHandler event.Handler CallerMap *event.CallerMap MouseTree *collision.Tree CollisionTree *collision.Tree KeyState *key.State }
A Context contains all transient engine components used in a scene, including the draw stack, event bus, known event callers, collision trees, keyboard state, and a reference to the OS window itself. When a scene ends, modifications made to these structures will be reset, excluding window modifications. TODO oak v4: consider embedding these system objects on the context to change ctx.DrawStack.Draw to ctx.Draw and ctx.EventHandler.Bind to ctx.Bind
func (*Context) DoAfter ¶
DoAfter will execute the given function after some duration. When the scene ends, DoAfter will exit without calling f. This call blocks until one of those conditions is reached.
func (*Context) DoAfterContext ¶
DoAfterContext will execute the given function once the passed in context is closed. When the scene ends, DoAfterContext will exit without calling f. This call blocks until one of those conditions is reached.
func (*Context) DrawForTime ¶
DrawForTime draws, and after d, undraws an element
type Map ¶
type Map struct { CurrentScene string // contains filtered or unexported fields }
A Map lets scenes be accessed via associated names.
func (*Map) AddScene ¶
AddScene takes a scene struct, checks that its assigned name does not conflict with an existing name in the map, and then adds it to the map. If a conflict occurs, the scene will not be overwritten. Checks if the Scene's start is nil, sets to noop if so. Checks if the Scene's loop is nil, sets to infinite if so. Checks if the Scene's end is nil, sets to loop to this scene if so.
func (*Map) Get ¶
Get returns the scene associated with the given name, if it exists. If it does not exist, it returns a zero value and false.
func (*Map) GetCurrent ¶
GetCurrent returns the current scene, as defined by map.CurrentScene
Example ¶
package main import ( "fmt" "github.com/oakmound/oak/v3/scene" ) func main() { m := scene.NewMap() sc := scene.Scene{ Start: func(*scene.Context) { fmt.Println("Starting screen one") }, } m.AddScene("screen1", sc) m.CurrentScene = "screen2" _, ok := m.GetCurrent() if !ok { fmt.Println("Screen two did not exist") } m.CurrentScene = "screen1" sc, ok = m.GetCurrent() if !ok { fmt.Println("Screen one did not exist") } else { sc.Start(&scene.Context{ PreviousScene: "scene0", }) } }
Output: Screen two did not exist Starting screen one
type Result ¶
type Result struct { NextSceneInput interface{} Transition }
A Result is a set of options for what should be passed into the next scene and how the next scene should be transitioned to.
type Scene ¶
type Scene struct { // Start is called when a scene begins, including contextual information like // what scene came before this one and a direct reference to clean data structures // for event handling and rendering Start func(ctx *Context) // If Loop returns true, the scene will continue // If Loop returns false, End will be called to determine the next scene Loop func() (cont bool) // End is a function returning the next scene and a SceneResult of // input settings for the next scene. End func() (nextScene string, result *Result) }
A Scene is a set of functions defining what needs to happen when a scene starts, loops, and ends.