Skip to content

Commit

Permalink
Merge pull request #292 from JiepengTan/builder#570_sprite_pivot
Browse files Browse the repository at this point in the history
#builder#570 sprite pivot
  • Loading branch information
xushiwei authored Jun 21, 2024
2 parents 03f76f4 + 24cf535 commit 8285bd8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/math32/vector2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions spgdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Sprite struct {
direction float64
rotationStyle RotationStyle
rRect *math32.RotatedRect
pivot math32.Vector2

sayObj *sayOrThinker
quoteObj *quoter
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8285bd8

Please sign in to comment.