diff --git a/config.go b/config.go index 833d8717..c9b67fb0 100644 --- a/config.go +++ b/config.go @@ -22,6 +22,7 @@ import ( "syscall" spxfs "github.com/goplus/spx/fs" + "github.com/goplus/spx/internal/math32" ) func resourceDir(resource interface{}) (fs spxfs.Dir, err error) { @@ -233,6 +234,7 @@ type spriteConfig struct { TAnimations map[string]*aniConfig `json:"tAnimations"` Visible bool `json:"visible"` IsDraggable bool `json:"isDraggable"` + Pivot math32.Vector2 `json:"pivot"` } func (p *spriteConfig) getCostumeIndex() int { diff --git a/internal/math32/vector2.go b/internal/math32/vector2.go index f1b7bf31..e1d5ebc1 100644 --- a/internal/math32/vector2.go +++ b/internal/math32/vector2.go @@ -6,8 +6,8 @@ import ( ) type Vector2 struct { - X float64 - Y float64 + X float64 `json:"x"` + Y float64 `json:"y"` } func NewVector2(x, y float64) *Vector2 { diff --git a/spgdi.go b/spgdi.go index b84147e0..80f9e0c9 100644 --- a/spgdi.go +++ b/spgdi.go @@ -134,6 +134,8 @@ func (p *spriteDrawInfo) updateMatrix() { c := p.sprite.costumes[p.sprite.costumeIndex_] img, centerX, centerY := c.needImage(p.sprite.g.fs) + centerX += p.sprite.pivot.X + centerY -= p.sprite.pivot.Y rect := image.Rectangle{} rect.Min.X = 0 rect.Min.Y = 0 diff --git a/sprite.go b/sprite.go index 35a2026d..ad6b7770 100644 --- a/sprite.go +++ b/sprite.go @@ -61,6 +61,7 @@ type Sprite struct { direction float64 rotationStyle RotationStyle rRect *math32.RotatedRect + pivot math32.Vector2 sayObj *sayOrThinker quoteObj *quoter @@ -109,8 +110,8 @@ func (p *Sprite) init( p.scale = sprite.Size p.direction = sprite.Heading p.rotationStyle = toRotationStyle(sprite.RotationStyle) - p.isVisible = sprite.Visible + p.pivot = sprite.Pivot p.animations = make(map[string]*aniConfig)