graphic

package module
v0.0.0-...-f96d276 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 9 Imported by: 0

README

go-graphic

pipeline status

dependendencies

to build go-sdl is required

info

go graphic is a library to quickly create a simple graphical output. NOTE: this project is currently may not work or frequently break with updates

version

this is the second stable version 0.2 Features:

  • load sprites from a json config + img files
  • create window from config file
  • log informantion in /tmp with the names WindowConfig.log SpriteConfig.log and name of the window.log
  • Render function to render every instance
  • add instances to every sprite
  • control instances by only changing der position tilt and center
  • add Sprite manually with imgPath or by ID of another sprite
  • render background with the same tools to render scenes
  • load background from image file
  • dump sprites
  • move the viewport around

Documentation

Overview

Package graphic is using the sdl2 go interface from (c)https://github.com/veandco/go-sdl2/ under the BSD 3 License

Package graphic is using the sdl2 go interface from (c)https://github.com/veandco/go-sdl2/ under the BSD 3 License

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(logger *log.Logger, name string) error

InitLogger sets the logger output to a file in /tmp

Types

type Config

type Config struct {
	Window      WindowConfig
	BaseSprites []SpriteBaseConfig
}

Config data loaded form config json

func (*Config) Load

func (config *Config) Load(windowJSON, spriteJSON string) error

Load Config from json files

type Instance

type Instance struct {
	DestRect sdl.FRect
	Angle    float64
	Center   sdl.FPoint
}

Instance position Angle and the Center of an instance of a sprite

func (*Instance) ChangePosition

func (instance *Instance) ChangePosition(x, y float32)

ChangePosition moves the instance by x, y

func (*Instance) NewPosition

func (instance *Instance) NewPosition(x, y float32)

NewPosition sets the position of this instance Center is the Center of the instances new position

type Sprite

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

Sprite contains the texture a list of instances and a srcRect

func NewSprite

func NewSprite(renderer *sdl.Renderer, imgPath string, srcRect sdl.Rect) (Sprite, error)

NewSprite creates a sprite based on a renderer, the image path and a src rectAngle

func (*Sprite) NewInstance

func (sprite *Sprite) NewInstance(x, y float32) *Instance

NewInstance adds a instance to the sprite and initializes the width and height of the dest rectAngle with the src rectAngle

type SpriteBaseConfig

type SpriteBaseConfig struct {
	ImgPath string
	Sprites []SpriteConfig
}

SpriteBaseConfig base config to create sprites on

type SpriteConfig

type SpriteConfig struct {
	Name    string
	SrcRect sdl.Rect
}

SpriteConfig config for a sprite based on a SpriteBaseConfig obj

type Window

type Window struct {
	Sprites []Sprite

	DrawColor struct {
		// contains filtered or unexported fields
	}
	Renderer *sdl.Renderer
	// contains filtered or unexported fields
}

Window contains the information required to render a window with diffrent Sprites

func (*Window) AddSprite

func (window *Window) AddSprite(imgPath string, srcRect sdl.Rect) (uint32, error)

AddSprite adds another sprite which can be used be creating a instance of it see Sprite.NewInstance

func (*Window) AddSpriteByID

func (window *Window) AddSpriteByID(spriteID uint32, srcRect sdl.Rect) uint32

AddSpriteByID adds another sprite with the same texture as sprite with id spriteID

func (*Window) Init

func (window *Window) Init(config WindowConfig) error

New returns a Window object with initialized renderer and window note that Sprites have to be added manual

func (*Window) LoadAndDumpSprites

func (window *Window) LoadAndDumpSprites(config []SpriteBaseConfig) (map[string]uint32, error)

LoadAndDumpSprites load new sprites and dump every old sprite and instance

func (*Window) LoadBackgroundImg

func (window *Window) LoadBackgroundImg(imgPath string) error

LoadBackgroundImg loads an image and uses it as the background

func (*Window) LoadSprites

func (window *Window) LoadSprites(config []SpriteBaseConfig) (map[string]uint32, error)

LoadSprites from config object returns map with sprite IDs linked to the sprite name

func (*Window) MoveView

func (window *Window) MoveView(x, y int32)

MoveView moves what you are seeing on screen

func (*Window) Render

func (window *Window) Render() error

Render renders the information from the window object to the screen

func (*Window) RenderBackground

func (window *Window) RenderBackground(w, h int32) error

RenderBackground by rendering current instances to work instances have to be created and should probably be dumped along with the sprites

func (*Window) SetView

func (window *Window) SetView(x, y int32)

SetView sets the x and y value of the viewport

type WindowConfig

type WindowConfig struct {
	Title                           string
	X, Y, Width, Height             int32
	WindowFlags, RendererFlags, FPS uint32
}

WindowConfig Render info for Window

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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