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

fix issue: Die behavior with animation #315 #331

Closed
wants to merge 6 commits into from
Closed
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
30 changes: 17 additions & 13 deletions sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,30 +485,24 @@ func (p *Sprite) OnTurning__1(onTurning func()) {
})
}

func (p *Sprite) Die() { // prototype sprite can't be destroyed, but can die
func (p *Sprite) Die() {
aniName := p.getStateAnimName(StateDie)
p.SetDying()

p.Stop(OtherScriptsInSprite)
if ani, ok := p.animations[aniName]; ok {
p.goAnimate(aniName, ani)
}
if p.isCloned_ {
p.doDestroy()
} else {
p.Hide()
}
}

func (p *Sprite) Destroy() { // delete this clone
if p.isCloned_ {
p.doDestroy()
}
p.Destroy()
}

func (p *Sprite) doDestroy() {
func (p *Sprite) Destroy() { // destroy sprite, whether prototype or cloned
if debugInstr {
log.Println("Destroy", p.name)
}
p.doStopSay()

p.Hide()
p.doDeleteClone()
p.g.removeShape(p)
p.Stop(ThisSprite)
Expand All @@ -517,6 +511,16 @@ func (p *Sprite) doDestroy() {
}
}

// delete only cloned sprite, no effect on prototype sprite.
// Add this interface, to match Scratch.
func (p *Sprite) DeleteThisClone() {
if !p.isCloned_ {
return
}

p.Destroy()
}

func (p *Sprite) Hide() {
if debugInstr {
log.Println("Hide", p.name)
Expand Down
Loading