1. Bullet Issue
- Posted by Icy_Viking 1 week ago
- 468 views
Hi all,
Why does the bullet appear to be shown as a growing longer circle when the bullet gets fired? Am I missing a certain step?
Using Greg's FFI Library and my Raylib wrapper version 5.5
[https://github.com/gAndy50/EuRayLib5/tree/main]
include std/ffi.e include raylib.e atom Width = 1024 atom Height = 720 InitWindow(Width,Height,"Bullets") SetTargetFPS(60) atom bullet_speed = 1.0 sequence bullets = {} integer bullet_visible = 0 sequence bullet_pos = {GetScreenWidth() / 2, GetScreenHeight() / 2} while not WindowShouldClose() do if IsKeyPressed(KEY_SPACE) then bullets = append(bullets,bullet_pos) bullet_visible = 1 end if for i = length(bullets) to 1 by -1 do bullet_pos[1] += bullet_speed if bullet_pos[1] >= GetScreenWidth() then bullets = remove(bullets,i) continue end if end for BeginDrawing() if bullet_visible = 1 then DrawCircleV(bullet_pos,20,RED) end if EndDrawing() end while CloseWindow()
2. Re: Bullet Issue
- Posted by andreasWagner 1 week ago
- 453 views
Hi all,
Why does the bullet appear to be shown as a growing longer circle when the bullet gets fired? Am I missing a certain step?
Using Greg's FFI Library and my Raylib wrapper version 5.5
[https://github.com/gAndy50/EuRayLib5/tree/main]
include std/ffi.e include raylib.e [...] BeginDrawing() if bullet_visible = 1 then DrawCircleV(bullet_pos,20,RED) end if EndDrawing()
Hi,
it seems you need to remove the last bullet before drawing the new on.
Like the code below, simply clears the background.
Andreas
BeginDrawing() if bullet_visible = 1 then ClearBackground(BLACK) DrawCircleV(bullet_pos,20,RED) end if EndDrawing()
3. Re: Bullet Issue
- Posted by Icy_Viking 1 week ago
- 421 views
Thanks that was it. It was refreshing as it drawing over the bullets.I made a few modifications. It works. Now I just need to add a small timer delay so the bullets don't get fired too fast.
include std/ffi.e include raylib.e atom Width = 1024 atom Height = 720 InitWindow(Width,Height,"Bullets") SetTargetFPS(60) atom bullet_speed = 1.0 sequence bullets = {} integer bullet_visible = 0 constant X = 1, Y = 2 sequence bullet_pos = {GetScreenWidth() / 2, GetScreenHeight() / 2} atom bullet_x = GetScreenWidth() / 2 atom bullet_y = GetScreenHeight() / 2 while not WindowShouldClose() do if IsKeyPressed(KEY_SPACE) then bullets = append(bullets,{bullet_x,bullet_y}) bullet_visible = 1 end if BeginDrawing() ClearBackground(BLACK) for i = length(bullets) to 1 by -1 do bullets[i][X] += bullet_speed if bullets[i][X] >= GetScreenWidth() then bullets = remove(bullets,i) continue end if if bullet_visible = 1 then --ClearBackground(BLACK) DrawCircleV({bullets[i][X],bullets[i][Y]},20,RED) end if end for DrawCircleV(bullet_pos,20,GREEN) EndDrawing() end while CloseWindow()