From 5fc2dd92ddbf663c01064385abdcd246b897f0c6 Mon Sep 17 00:00:00 2001 From: surdeus Date: Fri, 17 Feb 2023 18:56:15 +0500 Subject: [PATCH] Use pointer to object instead of struct for embedding. --- src/cmd/test/main.go | 10 ++++++++-- src/gx/object.go | 13 ++++--------- src/gx/sprite.go | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index 121927b..5f5db9d 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -5,7 +5,13 @@ import ( ) type Player struct { - gx.Object + *gx.Object +} + +func NewPlayer() *Player { + return &Player{ + Object: &gx.Object{}, + } } func main() { @@ -15,6 +21,6 @@ func main() { Height: 320, }) - e.Add(0, Player{}) + e.Add(0, NewPlayer()) e.Run() } diff --git a/src/gx/object.go b/src/gx/object.go index ab07de3..31b4dff 100644 --- a/src/gx/object.go +++ b/src/gx/object.go @@ -6,11 +6,6 @@ type Behaver interface { GetObject() *Object } -// The object that is drawn by sprite -/// based on the transform. -type Sprite struct { -} - // The object type represents // basic information for interaction // with the engine. @@ -19,9 +14,9 @@ type Object struct { } // The functions that -func (o Object) Start(e *Engine) {} -func (o Object) Update(e *Engine) {} -func (o Object) GetObject() *Object { - return &o +func (o *Object) Start(e *Engine) {} +func (o *Object) Update(e *Engine) {} +func (o *Object) GetObject() *Object { + return o } diff --git a/src/gx/sprite.go b/src/gx/sprite.go index ca27035..435dd6d 100644 --- a/src/gx/sprite.go +++ b/src/gx/sprite.go @@ -1,3 +1,4 @@ package gx - +type Sprite struct { +}