GithubHelp home page GithubHelp logo

How is Texture2D handled about raylib-lua HOT 2 CLOSED

tsnake41 avatar tsnake41 commented on June 14, 2024
How is Texture2D handled

from raylib-lua.

Comments (2)

TSnake41 avatar TSnake41 commented on June 14, 2024

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.

Ifelsethendo avatar Ifelsethendo commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.