manager

package module
v0.0.0-...-9f20e49 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 1 Imported by: 2

README

ebiten-manager

A very simple scene manager for ebiten

Usage

// scenes.MenuScene
var MenuScene *manager.Scene = &manager.Scene{
	Init: func(setReady func()) {
    // this has to be called to guarantee that we don't call anything before Init
		setReady()
	},
	Update: func(setReady func()) error {
		if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
			Context.Manager.SwitchTo("game")
		}
    // this has to be called to guarantee that we don't call Update before Draw
		setReady()
		return nil
	},
	Draw: func(screen *ebiten.Image) {
		ebitenutil.DebugPrint(screen, "Press ENTER to move to the game")
	},
}

// main.go
import manager "github.com/tducasse/ebiten-manager"

var m *manager.Manager
m = manager.MakeManager(map[string]*manager.Scene{
  "menu": scenes.MenuScene,
  "game": scenes.GameScene,
},
// the first scene 
"menu")

func (game *Game) Update() error {
	return m.Update()
}

func (game *Game) Draw(screen *ebiten.Image) {
	m.Draw(screen)
}

func (game *Game) Layout(w, h int) (int, int) {
	return screenWidth, screenHeight
}

type Game struct{}
var g *Game
g = &Game{}
ebiten.RunGame(g)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GameType

type GameType interface {
	Update() error
	Draw(screen *ebiten.Image)
	Init()
}

type Manager

type Manager struct {
	Scenes map[string]*Scene
	Data   map[string]interface{}
	Active *Scene
}

func MakeManager

func MakeManager(scenes map[string]*Scene, start string) *Manager

func (*Manager) Draw

func (m *Manager) Draw(screen *ebiten.Image)

func (*Manager) Init

func (m *Manager) Init()

func (*Manager) SwitchTo

func (m *Manager) SwitchTo(name string)

func (*Manager) Update

func (m *Manager) Update() error

type Scene

type Scene struct {
	Name        string
	Update      func(func()) error
	Draw        func(screen *ebiten.Image)
	Init        func(func())
	UpdateReady bool
	DrawReady   bool
}

func (*Scene) SetDrawReady

func (s *Scene) SetDrawReady()

func (*Scene) SetUpdateReady

func (s *Scene) SetUpdateReady()

Jump to

Keyboard shortcuts

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