binding

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package binding implements simple B system on top of window input methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type B

type B uint16

B is a arbitrary binding, should be declared with iota

type S

type S []state

S is collection of bindings, advantage over using just window is that you can send input over network easily and keep inputstate for each player. The way you should set up an inputstate is as follows:

 const (
		Forward binding.B = iota
		Right
    	Left
     Backwards
 )

 var Bindings = binging.New(key.W, key.D, key.A, key.S) // its a slice and you index into it with constants

Then each frame you can call Bindings.Update(win), though better approach is to Clone then and store with player for example. You can now create bindings with any key combination and listen to them with same constants. Other advantage is that you can Write and read bindings to netw.Buffer so stransporting input is lot easier.

func New

func New(keys ...key.Key) S

New creates binding mapping to witch you can index with your constant

func (S) Clone

func (s S) Clone() S

Clone clones the S (independent copy)

func (S) JustPressed

func (s S) JustPressed(bid B) bool

Pressed returns whether binding was pressed in this frame

panics at sam cases as State

func (S) JustReleased

func (s S) JustReleased(bid B) bool

Pressed returns whether binding was released in this frame

panics at sam cases as State

func (S) Pressed

func (s S) Pressed(bid B) bool

Pressed returns whether binding is pressed

panics at sam cases as State

func (S) Read

func (s S) Read(b *netw.Buffer)

Read reads S state from buffer

panics if length does not match

func (S) State

func (s S) State(bid B) State

State returns state of binding

panics if bid is indexing out of bounds, for example you registered les keys then there is iota constants

func (S) Update

func (s S) Update(w *ggl.Window) (changed bool)

Update updates S states and returns whether change happened

func (S) Write

func (s S) Write(b *netw.Buffer)

Write writes input to the buffer

type State

type State uint8

State stores Binding state

const (
	Released State = iota
	JustReleased
	Pressed
	JustPressed
)

State enum

Jump to

Keyboard shortcuts

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