Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#builder#570 sprite pivot #292

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading