Skip to content

Instantly share code, notes, and snippets.

@olso
Last active January 6, 2021 13:59
Show Gist options
  • Save olso/41ee5211283e78832080673709700725 to your computer and use it in GitHub Desktop.
Save olso/41ee5211283e78832080673709700725 to your computer and use it in GitHub Desktop.
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