Skip to content

Commit

Permalink
builder#570 sprite add extra pivot offset
Browse files Browse the repository at this point in the history
  • Loading branch information
JiepengTan committed Jun 20, 2024
1 parent 55a67ad commit d00a8fc
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 @@ -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 {
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 @@ -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)

Expand Down

0 comments on commit d00a8fc

Please sign in to comment.