mirror of
https://github.com/stevenhowes/GoRetro.git
synced 2026-05-26 15:53:31 +01:00
66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package GoRetro
|
|
|
|
/*
|
|
* --------------------
|
|
* spriteRenderer
|
|
* --------------------
|
|
* Loads a BMP into a texture and stores dimensions
|
|
*/
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
)
|
|
|
|
type spriteRenderer struct {
|
|
container *Element
|
|
tex *sdl.Texture
|
|
width, height int
|
|
}
|
|
|
|
func NewSpriteRenderer(container *Element, renderer *sdl.Renderer, filename string) *spriteRenderer {
|
|
sr := &spriteRenderer{}
|
|
var err error
|
|
|
|
filename = Config.DataDir + filename
|
|
sr.tex, err = loadTextureFromBMP(filename, renderer)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
_, _, width, height, err := sr.tex.Query()
|
|
if err != nil {
|
|
panic(fmt.Errorf("querying texture: %v", err))
|
|
}
|
|
sr.width = int(width)
|
|
sr.height = int(height)
|
|
|
|
sr.container = container
|
|
|
|
return sr
|
|
}
|
|
|
|
func (sr *spriteRenderer) onUpdate() error {
|
|
return nil
|
|
}
|
|
|
|
func (sr *spriteRenderer) onDraw() error {
|
|
Position := sr.container.Position
|
|
if !sr.container.PositionAbsolute {
|
|
Position = vectorAdd(sr.container.Position, ViewPort.Position)
|
|
}
|
|
|
|
return drawTexture(
|
|
sr.tex,
|
|
VectorInt32{-1, -1},
|
|
VectorInt32{0, 0},
|
|
Position,
|
|
sr.container.Rotation,
|
|
sr.container.Renderer)
|
|
}
|
|
|
|
func (sr *spriteRenderer) onCollision(other *Element) error {
|
|
return nil
|
|
}
|