gui

package
v0.0.0-...-b239de3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gui provides the graphical interface of the game world.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunGame

func RunGame(title string, world *core.World, speed int, mute bool) error

RunGame starts a GUI window and displays the specified world. The callUpdate option activates the core.WorldMap Update() call with 60 Ticks per second. Do not activate this option if the update is done externally.

This call is blocking.

Types

type Game

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

Game is the GUI

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

Draw draws the img screen by one frame.

The give argument represents a screen image. The updated content is adopted as the img screen.

func (*Game) Layout

func (g *Game) Layout(_, _ int) (int, int)

Layout accepts a native outside size in device-independent pixels and returns the img logical screen size.

On desktops, the outside is a window or a monitor (fullscreen mode). On browsers, the outside is a body element. On mobiles, the outside is the view's size.

Even though the outside size and the screen size differ, the rendering scale is automatically adjusted to fit with the outside.

Layout is called almost every frame.

It is ensured that Layout is invoked before Update is called in the first frame.

If Layout returns non-positive numbers, the caller can panic.

You can return a fixed screen size if you don't care, or you can also return a calculated screen size adjusted with the given outside size.

func (*Game) Update

func (g *Game) Update() error

Update updates an img by one tick. The given argument represents a screen image.

Update updates only the img logic and Draw draws the screen.

In the first frame, it is ensured that Update is called at least once before Draw. You can use Update to initialize the img state.

After the first frame, Update might not be called or might be called once or more for one frame. The frequency is determined by the current TPS (tick-per-second).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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