From 1e2e43ad2b149c7df6476dc90f54e910812280e6 Mon Sep 17 00:00:00 2001 From: surdeus Date: Fri, 28 Apr 2023 18:21:34 +0300 Subject: [PATCH] Implementing deleting objects. --- src/cmd/test/main.go | 2 ++ src/gx/main.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index 7a9fdd4..2ac24f7 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -94,6 +94,8 @@ func (p *Player) Update(e *gx.Engine) error { c.Object.T.RA.Y += gx.Pi * p.MoveSpeed * dt } log.Println(c.Object.T.RA.Y) + case ebiten.Key0 : + e.Del(p) }} return nil diff --git a/src/gx/main.go b/src/gx/main.go index 46ae1a7..56b49f9 100644 --- a/src/gx/main.go +++ b/src/gx/main.go @@ -77,6 +77,21 @@ func (e *Engine) Add(l Layer, b any) { } } +func (e *Engine) Del(b any) { + drawer, ok := b.(Drawer) + if ok { + for layer := range e.layers.Vals() { + layer.V.Del(drawer) + } + } + + behaver, ok := b.(Behaver) + if ok { + e.behavers.Del(behaver) + } + +} + func (e *Engine) AddDrawer(l Layer, d Drawer) { g, ok := e.layers.Get(l) if !ok {