mirror of
https://github.com/yeslayla/golang-game-framework.git
synced 2025-12-06 17:23:25 +01:00
Initial commit
This commit is contained in:
38
node/node2d.go
Normal file
38
node/node2d.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"github.com/manleydev/golang-game-framework/core"
|
||||
)
|
||||
|
||||
type Node2D struct {
|
||||
Node
|
||||
Position core.Vector2
|
||||
Rotation float64
|
||||
}
|
||||
|
||||
func (node *Node2D) GetPosition() core.Vector2 {
|
||||
return node.Position
|
||||
}
|
||||
|
||||
func (node *Node2D) GetGlobalPosition() core.Vector2 {
|
||||
if node.parent == nil {
|
||||
return node.Position
|
||||
}
|
||||
global2d, ok := (node.parent).(interface {
|
||||
GetGlobalPosition() core.Vector2
|
||||
})
|
||||
if ok {
|
||||
return node.Position.Add(global2d.GetGlobalPosition())
|
||||
}
|
||||
return node.Position
|
||||
}
|
||||
|
||||
func (node *Node2D) AddChild(child INode) {
|
||||
node.internalAddChild(node, child)
|
||||
}
|
||||
|
||||
func NewNode2D() Node2D {
|
||||
return Node2D{
|
||||
Node: NewNode(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user