gameloop

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 3 Imported by: 0

README

Plugin - Gameloop

A simple plugin that allows you to turn any pixel window into a managable entity that can be used in a game loop.

Defines an EasyWindow interface with the following methods

type EasyWindow interface {
	Win() *opengl.Window // get underlying GLFW window
	Setup() error         // setup window
	Update() error        // update window
	Draw() error          // draw to window
}

The loop in pseudo code looks like this:


win.Setup()

for !win.Closed() {
    win.Update()
    win.Draw()
}

Define your Update logic to handle user input and update the state of your game. Define your Draw logic to draw the state of your game to the window.

The game loop has the ability to handle multiple windows as well.

Example

package main

window1 := MyNewWindow() // assume MyNewWindow implements EasyWindow interface
window2 := MyOtherWindow() // assume MyOtherWindow implements EasyWindow interface

manager := NewWindowManager()
manager.InsertWindows([]opengl.EasyWindow{
    window1,
    window2,
})

manager.SetFPS(60) // set the FPS of the game loop

if err := manager.Loop(); err != nil {
    panic(err)
}

The above code will allow you to run a game loop with multiple windows. The manager assumes that the first window given to the InsertWindows method is the main window, and will block main loop until that main window is closed. The manager will then close all other windows and exit the game loop.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EasyWindow

type EasyWindow interface {
	Win() *opengl.Window // get underlying GLFW window
	Setup() error        // setup window
	Update() error       // update window
	Draw() error         // draw to window
}

type WindowManager

type WindowManager struct {
	Windows []EasyWindow
	// contains filtered or unexported fields
}

func NewWindowManager

func NewWindowManager() *WindowManager

func (*WindowManager) FPS

func (wm *WindowManager) FPS() float64

func (*WindowManager) InsertWindow

func (wm *WindowManager) InsertWindow(win EasyWindow) error

func (*WindowManager) InsertWindows

func (wm *WindowManager) InsertWindows(wins []EasyWindow) error

func (*WindowManager) Loop

func (wm *WindowManager) Loop() error

func (*WindowManager) SetFPS

func (wm *WindowManager) SetFPS(fps int) error

Jump to

Keyboard shortcuts

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