-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtextures_background_scrolling.lua
More file actions
62 lines (44 loc) · 1.9 KB
/
Copy pathtextures_background_scrolling.lua
File metadata and controls
62 lines (44 loc) · 1.9 KB
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
60
61
62
local screenWidth = 800
local screenHeight = 450
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling")
rl.SetTargetFPS(60)
local background = rl.LoadTexture("resources/cyberpunk_street_background.png")
local midground = rl.LoadTexture("resources/cyberpunk_street_midground.png")
local foreground = rl.LoadTexture("resources/cyberpunk_street_foreground.png")
local scrollingBack = 0.0
local scrollingMid = 0.0
local scrollingFore = 0.0
while not rl.WindowShouldClose() do
scrollingBack = scrollingBack - 0.1
scrollingMid = scrollingMid - 0.5
scrollingFore = scrollingFore - 1.0
if scrollingBack <= -background.width * 2 then
scrollingBack = 0
end
if scrollingMid <= -midground.width * 2 then
scrollingMid = 0
end
if scrollingFore <= -foreground.width * 2 then
scrollingFore = 0
end
rl.BeginDrawing()
rl.ClearBackground(rl.GetColor(0x052c46ff))
rl.ClearBackground(rl.RAYWHITE)
-- Draw background image twice
-- NOTE: Texture is scaled twice its size
rl.DrawTextureEx(background, { scrollingBack, 20 }, 0.0, 2.0, rl.WHITE)
rl.DrawTextureEx(background, { background.width * 2 + scrollingBack, 20 }, 0.0, 2.0, rl.WHITE)
--Draw midground image twice
rl.DrawTextureEx(midground, { scrollingMid, 20 }, 0.0, 2.0, rl.WHITE)
rl.DrawTextureEx(midground, { midground.width * 2 + scrollingMid, 20 }, 0.0, 2.0, rl.WHITE)
-- Draw foreground image twice
rl.DrawTextureEx(foreground, { scrollingFore, 70 }, 0.0, 2.0, rl.WHITE)
rl.DrawTextureEx(foreground, { foreground.width * 2 + scrollingFore, 70 }, 0.0, 2.0, rl.WHITE)
rl.DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, rl.RED)
rl.DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, rl.RAYWHITE)
rl.EndDrawing()
end
rl.UnloadTexture(background)
rl.UnloadTexture(midground)
rl.UnloadTexture(foreground)
rl.CloseWindow()