- Loading Fonts, Sounds Textures etc.
- Drawing Shapes and Graphics
- Images
Either use git clone or click the green "Code" button and download it in your project folder.
replace github.com/gen2brain/raylib-go/raylib => ./Raylib-Go-Wasm/raylib and then run go mod tidy
There is only one change you need to make!
In your file go to where you have defined
for !rl.WindowShouldClose(){and replace that with
var update = func(){after the function definition add the line
rl.SetMainLoop(update)
for !rl.WindowShouldClose(){
update()
}Look at this example if you dont understand.
See here
Comment the line
rl.SetMainLoop(update)and in your go.mod comment the line
replace github.com/gen2brain/raylib-go/raylib => ./Raylib-Go-Wasm/raylibFor MacOS and Linux:
GOOS=js GOARCH=wasm go build -o ./Raylib-Go-Wasm/index/main.wasm .For Windows Powershell:
$env:GOOS="js"; $env:GOARCH="wasm"; go build -o ./Raylib-Go-Wasm/index/main.wasm .For All platforms:
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" ./Raylib-Go-Wasm/index/wasm_exec.jsgo build ./Raylib-Go-Wasm/server/server.go./server
or if you're using Windows
./server.exe
this will serve your app on http://localhost:8080
I recommend you run the server in a seperate terminal, so you can recompile your code easier.
You can also setup air to automatically recompile your code when a file changes
firstly make sure air is installed and then make a file called .air.toml next to your main.go
(dont forget the dot in .air.toml)
put this in the file and simply run the air command while in the same directory as the .air.toml file
[build]
cmd = "GOOS=js GOARCH=wasm go build -o ./Raylib-Go-Wasm/index/main.wasm ."
bin = ""
include_ext = ["go"]
exclude_dir = ["vendor"]
delay = 100
[log]
time = falsecopy the contents of the folder Raylib-Go-Wasm/index into your github pages repository