forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (40 loc) · 1.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
frameWidth := float32(scarfy.Width) / 7
frameHeight := float32(scarfy.Height)
// NOTE: Source rectangle (part of the texture to use for drawing)
sourceRec := rl.NewRectangle(0, 0, frameWidth, frameHeight)
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
destRec := rl.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
origin := rl.NewVector2(float32(frameWidth), float32(frameHeight))
rotation := float32(0)
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
// Update
rotation++
// Draw
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
// sourceRec defines the part of the texture we use for drawing
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
// origin defines the point of the texture used as reference for rotation and scaling
// rotation defines the texture rotation (using origin as rotation point)
rl.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, rl.White)
rl.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, rl.Gray)
rl.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), rl.Gray)
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
rl.EndDrawing()
}
rl.UnloadTexture(scarfy)
rl.CloseWindow()
}