Fix some issues in examples and favor vsync instead of fps locking.

This commit is contained in:
TSnake41 2020-03-29 15:40:02 +02:00
parent 83e4094cf6
commit ada4f23d2b
4 changed files with 127 additions and 129 deletions

View File

@ -1,8 +1,6 @@
setmetatable(_G, { __index = rl })
SetConfigFlags(FLAG_VSYNC_HINT)
SetTargetFPS(60)
InitWindow(800, 450, "raylib [lua] example - global api")
while not WindowShouldClose() do

View File

@ -5,7 +5,7 @@ local screenHeight = 450
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT)
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib-lua] - Physics demo")
rl.InitWindow(screenWidth, screenHeight, "Physac [raylua] - Physics demo")
local logoX = screenWidth - rl.MeasureText("Physac", 30) - 10
local logoY = 15

View File

@ -1,11 +1,9 @@
local ffi = require "ffi"
local lua_color = ffi.new("Color", 3, 3, 128, 255)
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.SetTargetFPS(60)
local width, height = 800, 450
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.InitWindow(800, 450, "raylib [shapes] example - basic shapes drawing")
while not rl.WindowShouldClose() do

View File

@ -9,6 +9,7 @@
--
--------------------------------------------------------------------------------------------
local ffi = require "ffi"
local bit = require "bit"
local MAX_BUNNIES = 100000 -- 100K bunnies limit
@ -17,8 +18,9 @@ local MAX_BUNNIES = 100000 -- 100K bunnies limit
local MAX_BATCH_ELEMENTS = 8192
-- Create the Bunny class.
Bunny = {}
local Bunny = {}
Bunny.__index = Bunny
function Bunny:new(pos, spd, col)
local bunny = {}
setmetatable(bunny,Bunny)
@ -27,13 +29,16 @@ function Bunny:new(pos, spd, col)
bunny.color = col
return bunny
end
function Bunny:update(texture)
self.position.x = self.position.x + self.speed.x
self.position.y = self.position.y + self.speed.y
if ((self.position.x + texture.width/2) > rl.GetScreenWidth()) or ((self.position.x + texture.width/2) < 0) then
if ((self.position.x + texture.width/2) > rl.GetScreenWidth())
or ((self.position.x + texture.width/2) < 0) then
self.speed.x = self.speed.x * -1
end
if ((self.position.y + texture.height/2) > rl.GetScreenHeight()) or ((self.position.y + texture.height/2 - 40) < 0) then
if ((self.position.y + texture.height/2) > rl.GetScreenHeight())
or ((self.position.y + texture.height/2 - 40) < 0) then
self.speed.y = self.speed.y * -1
end
end
@ -43,14 +48,13 @@ end
local screenWidth = 800
local screenHeight = 450
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark")
-- Load bunny texture
local texBunny = rl.LoadTexture("resources/wabbit_alpha.png")
local bunnies = {}
rl.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
----------------------------------------------------------------------------------------
-- Main game loop
@ -77,11 +81,11 @@ while not rl.WindowShouldClose() do -- Detect window close button or ESC key
-- Draw
------------------------------------------------------------------------------------
rl.BeginDrawing();
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.RAYWHITE)
for i = 1, #bunnies do
for i=1,#bunnies do
-- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
-- a draw call is launched and buffer starts being filled again;
-- before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
@ -94,8 +98,6 @@ while not rl.WindowShouldClose() do -- Detect window close button or ESC key
rl.DrawRectangle(0, 0, screenWidth, 40, rl.BLACK)
rl.DrawText("bunnies: " .. #bunnies, 120, 10, 20, rl.GREEN)
rl.DrawText("batched draw calls: " .. math.ceil(1 + #bunnies / MAX_BATCH_ELEMENTS), 320, 10, 20, rl.MAROON)
-- DrawText(FormatText("bunnies: %i", #bunnies), 120, 10, 20, GREEN)
-- DrawText(FormatText("batched draw calls: %i", 1 + #bunnies/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON)
rl.DrawFPS(10, 10)