From d00a8fcfa461e3305f11c9d035d3f1683511b0d2 Mon Sep 17 00:00:00 2001 From: jiepengtan Date: Thu, 20 Jun 2024 14:45:19 +0800 Subject: [PATCH 1/2] builder#570 sprite add extra pivot offset --- config.go | 2 ++ internal/math32/vector2.go | 4 ++-- spgdi.go | 2 ++ sprite.go | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 8972ff5..26c9e16 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) { @@ -232,6 +233,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 f1b7bf3..e1d5ebc 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 b84147e..b66cce3 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 187b20a..1dde498 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 @@ -108,8 +109,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) From 24cf5358632541668ee7f420e322c63365daa4c8 Mon Sep 17 00:00:00 2001 From: jiepengtan Date: Thu, 20 Jun 2024 14:54:18 +0800 Subject: [PATCH 2/2] invert y axis (ebiten use texture coord) --- spgdi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spgdi.go b/spgdi.go index b66cce3..80f9e0c 100644 --- a/spgdi.go +++ b/spgdi.go @@ -135,7 +135,7 @@ func (p *spriteDrawInfo) updateMatrix() { img, centerX, centerY := c.needImage(p.sprite.g.fs) centerX += p.sprite.pivot.X - centerY += p.sprite.pivot.Y + centerY -= p.sprite.pivot.Y rect := image.Rectangle{} rect.Min.X = 0 rect.Min.Y = 0