Comments (2)
You may not be using raylib-lua but possibly another lua binding such as https://github.com/Rabios/raylua.
Anyway, the code you provided had some issues with Lua syntax, like (Vector2){ ... }
which is invalid (it's either Vector2(...)
or rl.new("Vector2", ...)
or rl.Vector2(...)
depending of the binding used.
A fixed code, that works with https://github.com/TSnake41/raylib-lua
local screenWidth = 800
local screenHeight = 450
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling")
rl.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
-- NOTE: Be careful, background width must be equal or bigger than screen width
-- if not, texture should be draw more than two times for scrolling effect
background = rl.LoadTexture("cyberpunk_street_background.png")
midground = rl.LoadTexture("cyberpunk_street_midground.png")
foreground = rl.LoadTexture("cyberpunk_street_foreground.png")
scrollingBack = 0.0
scrollingMid = 0.0
scrollingFore = 0.0
while not rl.WindowShouldClose() do -- Detect window close button or ESC key
-- Update
------------------------------------------------------------------------------------
scrollingBack = scrollingBack- 0.1
scrollingMid = scrollingMid- 0.5
scrollingFore = scrollingFore- 1.0
-- NOTE: Texture is scaled twice its size, so it sould be considered on scrolling
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
-- Draw
-----------------------------------------------------------------------------------
rl.BeginDrawing()
--ClearBackground(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
-- De-Initialization
----------------------------------------------------------------------------------------
rl.UnloadTexture(background) -- Unload background texture
rl.UnloadTexture(midground) -- Unload midground texture
rl.UnloadTexture(foreground) -- Unload foreground texture
rl.CloseWindow() -- Close window and OpenGL context
----------------------------------------------------------------------------------------
In my case, I don't see any issues with background, maybe the problem is elsewhere ?
from raylib-lua.
Great, That Works! yeah I was afraid the bindings might get mixed up, but thought yours was the only LuaJit one(?) Things got mixed up when trying to use ZeroBrane, It couldn't find a lot of what it was looking for until I set the project directory, so I had just dumped every rayLib Lua on earth into a folder hoping something would work. I better do a clean install of everything so things aren't a mess. Thanks for the response!
from raylib-lua.
Related Issues (14)
- missing declaration for symbol 'CreateLight' HOT 2
- My collision system no longer works HOT 1
- Part of the `README.md` lists "3.5" as a version, but elsewhere the library is claimed to be "4.5". Which is correct? HOT 1
- Explain the purpose of `raylua_r` in `README.md` HOT 4
- error while using local raylib = require("raylib") HOT 1
- Error trying to initialize a window HOT 2
- How does this system work
- Building on Windows HOT 3
- Audio doesnt work in embedded mode
- `varargs` and the `arg` hidden parameter don't work correctly HOT 1
- Request, or instructions, to create a custom version of raylua HOT 2
- raylib-lua is slow on Apple M1 HOT 6
- Unable to use DrawTextEx HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raylib-lua.