From 98343713c2ae5a5256b43fdbd1787fe749ca2c18 Mon Sep 17 00:00:00 2001 From: Dima Marhitych Date: Sun, 8 Oct 2023 17:47:31 +0200 Subject: [PATCH] v0.0.9: Fixed a bug --- src/backend/document/canvas.go | 4 ++++ src/webzen/init.go | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/backend/document/canvas.go b/src/backend/document/canvas.go index 0434dc2..ae58f49 100644 --- a/src/backend/document/canvas.go +++ b/src/backend/document/canvas.go @@ -41,6 +41,10 @@ func (c *context) FillRect(x, y, width, height float64) { c.context.Call("fillRect", x, y, width, height) } +func (c *context) ClearRect(x, y, width, height float64) { + c.context.Call("clearRect", x, y, width, height) +} + func (c *context) DrawImage(img js.Value, x, y, width, height float64) { c.context.Call("drawImage", img, x, y, width, height) } diff --git a/src/webzen/init.go b/src/webzen/init.go index 8c2228c..8e1cb68 100644 --- a/src/webzen/init.go +++ b/src/webzen/init.go @@ -5,17 +5,23 @@ package webzen import ( "syscall/js" - "time" + "time" "github.com/dimkauzh/webzen/src/backend/document" "github.com/dimkauzh/webzen/src/backend/window" - "github.com/dimkauzh/webzen/src/webzen/keys" + "github.com/dimkauzh/webzen/src/webzen/keys" ) var fpsInterval = time.Millisecond * 16 func SetFps(fps int) { - fpsInterval = time.Second / time.Duration(fps) + fpsInterval = time.Second / time.Duration(fps) +} + +func clearCanvas() { + canvas := document.GetElementById("canvas") + context := canvas.GetContext("2d") + context.ClearRect(0, 0, canvas.Get("width").Float(), canvas.Get("height").Float()) } func Init() { @@ -38,9 +44,10 @@ func Init() { return nil })) - keys.SetupEventListeners() + keys.SetupEventListeners() } func Update() { - time.Sleep(time.Millisecond * 16) + time.Sleep(time.Millisecond * 16) + clearCanvas() }