Last active
January 6, 2021 13:59
-
-
Save olso/41ee5211283e78832080673709700725 to your computer and use it in GitHub Desktop.
https://github.com/olso/go-wasm-cat-game-on-canvas-with-docker 🧶 https://olso.space 🧶 https://twitter.com/olso_uznebolo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
setup() | |
// declare renderer at compile time | |
var renderer js.Func | |
// looks like JS callback, right 😌 | |
renderer = js.FuncOf(func(this js.Value, args []js.Value) interface{} { | |
updateGame() | |
// for the 60fps anims | |
window.Call("requestAnimationFrame", renderer) | |
return nil | |
}) | |
window.Call("requestAnimationFrame", renderer) | |
// let's handle that mouse/touch down | |
var mouseEventHandler js.Func = js.FuncOf(func(this js.Value, args []js.Value) interface{} { | |
updatePlayer(args[0]) | |
return nil | |
}) | |
window.Call("addEventListener", "pointerdown", mouseEventHandler) | |
} | |
func updatePlayer(event js.Value) {} | |
func updateGame() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment