From d9affe0462cd0948b45aa0bf5dfb6cf387a1000d Mon Sep 17 00:00:00 2001 From: qlli Date: Fri, 6 Sep 2024 09:26:05 +0800 Subject: [PATCH] fix: Initial costumeIndex for sprite not working #317 --- sprite.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sprite.go b/sprite.go index 62778cb0..be547c75 100644 --- a/sprite.go +++ b/sprite.go @@ -118,6 +118,7 @@ func (p *Sprite) init( } else { p.baseObj.initWith(base, sprite, shared) } + p.defaultCostumeIndex = p.baseObj.costumeIndex_ p.eventSinks.init(&g.sinkMgr, p) p.gamer = gamer @@ -221,7 +222,7 @@ func (p *Sprite) init( } } func (p *Sprite) awake() { - p.playDefaultAnim() + p.playDefaultAnim(false) } func (p *Sprite) InitFrom(src *Sprite) { @@ -786,7 +787,7 @@ func (p *Sprite) goAnimateInternal(name string, ani *aniConfig, isBlocking bool) waitToDo(animwg.Wait) } if isNeedPlayDefault { - p.playDefaultAnim() + p.playDefaultAnim(true) } } @@ -928,7 +929,7 @@ func (p *Sprite) Step__2(step float64, animname string) { p.goMoveForward(step) } -func (p *Sprite) playDefaultAnim() { +func (p *Sprite) playDefaultAnim(resetCostume bool) { animName := p.defaultAnimation if p.isVisible { isPlayAnim := false @@ -940,7 +941,7 @@ func (p *Sprite) playDefaultAnim() { p.goAnimateInternal(animName, &anicopy, false) } } - if !isPlayAnim { + if resetCostume && !isPlayAnim { p.goSetCostume(p.defaultCostumeIndex) } }