mirror of
https://github.com/stevenhowes/GoRetro.git
synced 2026-05-27 00:03:29 +01:00
Render sprites from sprite sheets (no animation yet)
This commit is contained in:
+15
-5
@@ -10,6 +10,8 @@ var TexList map[string]*sdl.Texture
|
||||
|
||||
func drawTexture(
|
||||
tex *sdl.Texture,
|
||||
size VectorInt32,
|
||||
sheetposition VectorInt32,
|
||||
position Vector,
|
||||
rotation float64,
|
||||
renderer *sdl.Renderer) error {
|
||||
@@ -19,16 +21,24 @@ func drawTexture(
|
||||
return fmt.Errorf("querying texture: %v", err)
|
||||
}
|
||||
|
||||
// If we're given -1,-1 for the size then we're using the entire texture
|
||||
if size.X < 0 {
|
||||
size.X = width
|
||||
}
|
||||
if size.Y < 0 {
|
||||
size.Y = height
|
||||
}
|
||||
|
||||
// Convert coordinates to the top left of the sprite
|
||||
position.X -= float64(width) / 2.0
|
||||
position.Y -= float64(height) / 2.0
|
||||
position.X -= float64(size.X) / 2.0
|
||||
position.Y -= float64(size.Y) / 2.0
|
||||
|
||||
return renderer.CopyEx(
|
||||
tex,
|
||||
&sdl.Rect{X: 0, Y: 0, W: width, H: height},
|
||||
&sdl.Rect{X: int32(position.X), Y: int32(position.Y), W: width, H: height},
|
||||
&sdl.Rect{X: sheetposition.X, Y: sheetposition.Y, W: size.X, H: size.Y},
|
||||
&sdl.Rect{X: int32(position.X), Y: int32(position.Y), W: size.X, H: size.Y},
|
||||
rotation,
|
||||
&sdl.Point{X: width / 2, Y: height / 2},
|
||||
&sdl.Point{X: size.X / 2, Y: size.Y / 2},
|
||||
sdl.FLIP_NONE)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user