rayframe

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: BSD-3-Clause Imports: 3 Imported by: 4

README

Rayframe

Rayframe is a raylib framework for Go.

Use

Creating a framework

Instantiate a *rayframe.RayFrame:

frame := &rayframe.RayFrame{}

The fields you can set are:

  • Camera *raylib.Camera: for 3D rendering
  • FPS int: how many frames per second
  • InFront3D bool: whether 3D must be rendered in front of 2D rendering
  • OnResize func(int, int, boot): a callback called whenever the window is resized, passing the new size (width and height) and whether it’s fullscreen.

The fields you can read:

  • Tick time.Time: last tick time
  • WindowSize struct{ X, Y int }: current window size
Starting the framework

Initialise the framework by calling:

frame.Init(1280, 720, "My Application")

The parameters are:

  1. width int: window initial width
  2. height int: window initial height
  3. title string: window title

Then start the main loop by calling:

frame.Mainloop(scene)

scene can be any structure pointer.

Scene is an alias to interface{}.

Scene

Each scene may implement any of the following methods:

  • Init(*rayframe.RayFrame): called when the framework shifts to the scene.
  • Background() color.RBGA: inform the framework which colour to use when painting the background. If not implemented, the framework won’t call raylib.ClearBackground().
  • ExitKey() int32: which key is used to exit, default to raylib.KeyEscape. Only works associated with OnKeyEscape(). Use zero (0) to disable the exit key.
  • OnKeyEscape() Scene: what to do when the escape key is pressed. Only works associated with ExitKey(). Return nil or the scene itself to do nothing.
  • Update(time.Duration) Scene: called each tick and receives the time delta since the last tick.
  • Render2D() Scene: used to render 2D assets.
  • Render3D() Scene: used to render 3D assets under 3D mode, if the framework’s Camera is set.

If any Scene-returning method returns anything but the calling scene itself, the framework will change the scene by the return value and will call Init() (if it’s implemented).

License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackgroundScene

type BackgroundScene interface {
	Background() color.RGBA
}

type ExitKeyScene added in v1.2.1

type ExitKeyScene interface {
	ExitKey() int32
	OnKeyEscape() Scene
}

type InitScene

type InitScene interface {
	Init(*RayFrame)
}

type RayFrame

type RayFrame struct {
	Camera     *raylib.Camera
	FPS        int
	InFront3D  bool
	OnResize   func(int, int, bool)
	Tick       time.Time
	WindowSize intVector2D
}

func (*RayFrame) Init

func (frame *RayFrame) Init(width, height int, title string)

func (*RayFrame) Mainloop

func (frame *RayFrame) Mainloop(initialScene Scene)

type RendererScene2D

type RendererScene2D interface {
	Render2D() Scene
}

type RendererScene3D

type RendererScene3D interface {
	Render3D() Scene
}

type Scene added in v1.2.0

type Scene = interface{}

type UpdateScene added in v0.1.2

type UpdateScene interface {
	Update(time.Duration) Scene
}

Jump to

Keyboard shortcuts

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