Use pointer to object instead of struct for embedding.

This commit is contained in:
Andrey Parhomenko 2023-02-17 18:56:15 +05:00
parent c9f8027f81
commit 5fc2dd92dd
3 changed files with 14 additions and 12 deletions

View file

@ -5,7 +5,13 @@ import (
) )
type Player struct { type Player struct {
gx.Object *gx.Object
}
func NewPlayer() *Player {
return &Player{
Object: &gx.Object{},
}
} }
func main() { func main() {
@ -15,6 +21,6 @@ func main() {
Height: 320, Height: 320,
}) })
e.Add(0, Player{}) e.Add(0, NewPlayer())
e.Run() e.Run()
} }

View file

@ -6,11 +6,6 @@ type Behaver interface {
GetObject() *Object GetObject() *Object
} }
// The object that is drawn by sprite
/// based on the transform.
type Sprite struct {
}
// The object type represents // The object type represents
// basic information for interaction // basic information for interaction
// with the engine. // with the engine.
@ -19,9 +14,9 @@ type Object struct {
} }
// The functions that // The functions that
func (o Object) Start(e *Engine) {} func (o *Object) Start(e *Engine) {}
func (o Object) Update(e *Engine) {} func (o *Object) Update(e *Engine) {}
func (o Object) GetObject() *Object { func (o *Object) GetObject() *Object {
return &o return o
} }

View file

@ -1,3 +1,4 @@
package gx package gx
type Sprite struct {
}