Skip to content

Commit

Permalink
Merge pull request #329 from qlli/main
Browse files Browse the repository at this point in the history
fix: Unify Die behavior of initial / cloned sprite #314
  • Loading branch information
xushiwei committed Sep 11, 2024
2 parents 1b3a5bf + 7462a9d commit b1f0ef6
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,30 +485,22 @@ 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()
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 +509,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

0 comments on commit b1f0ef6

Please sign in to comment.