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: Unify Die behavior of initial / cloned sprite #314 #329

Merged
merged 4 commits into from
Sep 11, 2024
Merged
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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As proposed here, a public method named DeleteThisClone is expected to be offered:

  • Rename current destroy to deleteThisClone for compatibility with Scratch's 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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is advisable to comment for the purpose of DeleteThisClone here, as it appears redundant with Destroy and Die provided.

if !p.isCloned_ {
return
}

p.Destroy()
}

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