bamenn

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Bamenn

Simple scene library for Ebitengine.

This library provides the ability to run multiple ebiten.Game s in sequence, with each ebiten.Game as a single scene.

Key features: Sequence and Transition types

Sequence structure runs multiple ebiten.Game s in sequence. You can switch ebiten.Game s with Sequence.Switch or Sequence.SwitchWithTransition. Transition is used to draw (e.g. fade in and out) when switching between ebiten.Game.

Sequence also implements ebiten.Game.

Event functions

If ebiten.Game implements some or all of the OnStarter, OnArrivaler, OnDeparturer and OnEnder interfaces, they are called at the following times:

OnStarter

OnStarter.OnStart is called immediately after ebiten.Game is switched.

It is called just before the first ebiten.Game.Update after the game starts.

OnArrivaler

OnArrivaler.OnArrival is called when the switched ebiten.Game starts and the Transition process is complete. For example, when the fade-in is complete. This function is useful, for example, to enable player input upon completion of a scene transition.

It is called just before the first ebiten.Game.Update after the game starts and after OnStarter.OnStart.

OnDeparturer

OnDeparturer.OnDeparture is called when a Transition is started to switch scenes. This is useful to disable player input at the beginning of a scene transition.

It is not called when the game is terminated by ebiten.Termination.

OnEnder

OnEnder.OnEnd is called just before ebiten.Game switches.

It is not called when the game is terminated by ebiten.Termination.

Parallel type

Parallel structure handles multiple ebiten.Games in parallel. The order of processing is constant.

Parallel.Layout calls all ebiten.Game.Layout and returns the largest return value.

Limitations

  • OnStarter, OnArrivaler, OnDeparturer and OnEnder are called by Sequence. Use Sequence to enable them.
  • When switching scenes, ebiten.Game.Layout of the previous scene may be called. If the sizes returned by the previous and following ebiten.Game.Layout are different, the size of the screen passed to ebiten.Game.Draw after the changeover may be unintended.

How to add to your project

Add the dependency with go get command.

go get github.com/noppikinatta/bamenn

How to use

See examples.

https://github.com/noppikinatta/bamenn/tree/main/examples

Documentation

Overview

Package bamenn provides the ability to manage Ebitengine game scenes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinearTransition

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

LinearTransition is a Transition that transitions linearly for a specified number of frames.

func NewLinearTransition

func NewLinearTransition(frameToSwitch, maxFrames int, drawer LinearTransitionDrawer) *LinearTransition

NewLinearTransition returns a new LinearTransition.

func (*LinearTransition) CanSwitchScenes

func (t *LinearTransition) CanSwitchScenes() bool

CanSwitchScenes returns true when ebiten.Game, which represents a scene, can be switched. Even if true is returned at multiple frames during a single scene transition, the scene is switched only once. If CanSwitchScenes does not return true, the scene switch will occur when Completed returns true.

func (*LinearTransition) Completed

func (t *LinearTransition) Completed() bool

Completed returns true when the scene transition is complete.

func (*LinearTransition) Draw

func (t *LinearTransition) Draw(screen *ebiten.Image)

Draw draws during scene transitions. The argument screen reflects the result of drawing by ebiten.Game.Draw.

func (*LinearTransition) Progress

Progress returns the progress of it.

func (*LinearTransition) Reset

func (t *LinearTransition) Reset()

Reset is called at the start of a scene transition. If the same instance is to be used multiple times, Reset should be used to initialize the Transition state.

func (*LinearTransition) Update

func (t *LinearTransition) Update() error

Update is called in ebiten.Game.Update to update the state of Transition.

type LinearTransitionDrawer

type LinearTransitionDrawer interface {
	// Draw draws as the LinearTransition progresses.
	Draw(screen *ebiten.Image, progress LinearTransitionProgress)
}

LinearTransitionDrawer is an interface that draws as the LinearTransition progresses.

type LinearTransitionProgress

type LinearTransitionProgress struct {
	CurrentFrame  int // CurrentFrame is the current frame.
	MaxFrames     int // MaxFrames is the maximum number of frames.
	FrameToSwitch int // FrameToSwitch returns the frame to switch scenes.
}

LinearTransitionProgress represents the progress of LinearTransition.

func (LinearTransitionProgress) Rate

Rate returns the progress rate of LinearTransition in the range of 0.0~1.0.

type OnArrivaler

type OnArrivaler interface {
	OnArrival()
}

OnArrivaler is an interface that executes processing when a scene begins and the beginning transition is completed.

type OnDeparturer

type OnDeparturer interface {
	OnDeparture()
}

OnDeparturer is an interface that executes processing when a scene ends and the ending transition begins.

type OnEnder

type OnEnder interface {
	// OnEnd is called just before the end of the scene.
	OnEnd()
}

OnEnder is an interface that executes processing at the end of a scene.

type OnStarter

type OnStarter interface {
	// OnStart is called immediately after the start of the scene.
	OnStart()
}

OnStarter is an interface that executes processing at the start of a scene.

type Parallel

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

Parallel runs multiple Games in parallel.

func NewParallel

func NewParallel(games ...ebiten.Game) *Parallel

NewParallel creates a new Parallel instance.

func (*Parallel) Draw

func (p *Parallel) Draw(screen *ebiten.Image)

Draw is ebiten.Game implementation. it calls all ebiten.Game.Draw in the order of index.

func (*Parallel) DrawFinalScreen

func (p *Parallel) DrawFinalScreen(screen ebiten.FinalScreen, offScreen *ebiten.Image, geoM ebiten.GeoM)

DrawFinalScreen is ebiten.FinalScreenDrawer implementation. It calls only the DrawFinalScreen of the lowest index that implements FinalScreenDrawer among the Games it holds.

func (*Parallel) Layout

func (p *Parallel) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

Layout is ebiten.Game implementation. It returns the largest width and height of all Layouts.

func (*Parallel) LayoutF

func (p *Parallel) LayoutF(outsideWidth, outsideHeight float64) (screenWidth, screenHeight float64)

LayoutF is ebiten.LayoutFer implementation. It returns the largest width and height of all LayoutFs.

func (*Parallel) OnArrival

func (p *Parallel) OnArrival()

OnArrival is OnArrivaler implementation. it calls all OnArrivaler.OnArrival in the order of index if implemented.

func (*Parallel) OnDeparture

func (p *Parallel) OnDeparture()

OnDeparture is OnDeparturer implementation. it calls all OnDeparturer.OnDeparture in the order of index if implemented.

func (*Parallel) OnEnd

func (p *Parallel) OnEnd()

OnEnd is OnEnder implementation. it calls all OnEnder.OnEnd in the order of index if implemented.

func (*Parallel) OnStart

func (p *Parallel) OnStart()

OnStart is OnStarter implementation. it calls all OnStarter.OnStart in the order of index if implemented.

func (*Parallel) Update

func (p *Parallel) Update() error

Update is ebiten.Game implementation. it calls all ebiten.Game.Update in the order of index. All Updates are called and errors are joined.

type Sequence

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

Sequence provides the ability to run multiple ebiten.Games in sequence.

func NewSequence

func NewSequence(first ebiten.Game) *Sequence

NewSequence creates a new Sequence instance with the first scene.

func (*Sequence) Draw

func (s *Sequence) Draw(screen *ebiten.Image)

Draw is ebiten.Game implementation.

func (*Sequence) DrawFinalScreen

func (s *Sequence) DrawFinalScreen(screen ebiten.FinalScreen, offScreen *ebiten.Image, geoM ebiten.GeoM)

DrawFinalScreen is ebiten.FinalScreenDrawer implementation.

func (*Sequence) Layout

func (s *Sequence) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

Layout is ebiten.Game implementation.

func (*Sequence) LayoutF

func (s *Sequence) LayoutF(outsideWidth, outsideHeight float64) (screenWidth, screenHeight float64)

LayoutF is ebiten.LayoutFer implementation.

func (*Sequence) OnArrival

func (s *Sequence) OnArrival()

OnArrival is OnArrivaler implementation.

func (*Sequence) OnDeparture

func (s *Sequence) OnDeparture()

OnDeparture is OnDeparturer implementation.

func (*Sequence) OnEnd

func (s *Sequence) OnEnd()

OnEnd is OnEnder implementation.

func (*Sequence) OnStart

func (s *Sequence) OnStart()

OnStart is OnStarter implementation.

func (*Sequence) SetFirst added in v0.2.0

func (s *Sequence) SetFirst(first ebiten.Game)

SetFirst sets the first scene to be handled by it. It is intended for use when setting up the first scene. Do not use it to switch between scenes.

func (*Sequence) Switch

func (s *Sequence) Switch(next ebiten.Game) bool

Switch switches the ebiten.Game to run in Sequence.

func (*Sequence) SwitchWithTransition

func (s *Sequence) SwitchWithTransition(next ebiten.Game, transition Transition) bool

SwitchWithTransition switches the ebiten.Game to run in Sequence with the Transition.

func (*Sequence) Update

func (s *Sequence) Update() error

Update is ebiten.Game implementation.

type Transition

type Transition interface {
	// Reset is called at the start of a scene transition.
	// If the same instance is to be used multiple times, Reset should be used to initialize the Transition state.
	Reset()
	// Update is called in ebiten.Game.Update to update the state of Transition.
	Update() error
	// Draw draws during scene transitions.
	// The argument screen reflects the result of drawing by ebiten.Game.Draw.
	Draw(screen *ebiten.Image)
	// Completed returns true when the scene transition is complete.
	Completed() bool
	// CanSwitchScenes returns true when ebiten.Game, which represents a scene, can be switched.
	// Even if true is returned at multiple frames during a single scene transition, the scene is switched only once.
	// If CanSwitchScenes does not return true, the scene switch will occur when Completed returns true.
	CanSwitchScenes() bool
}

Transition is an interface for drawing during scene transitions.

var NopTransition Transition = nopTransition{}

NopTransition is a Transition that does not draw anything.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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