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

Unify Die behavior of initial / cloned sprite #314

Closed
nighca opened this issue Aug 20, 2024 · 2 comments
Closed

Unify Die behavior of initial / cloned sprite #314

nighca opened this issue Aug 20, 2024 · 2 comments

Comments

@nighca
Copy link
Collaborator

nighca commented Aug 20, 2024

In SPX, there are different implementations of the Die method for initial and cloned sprites:

spx/sprite.go

Lines 483 to 494 in 3df776b

func (p *Sprite) Die() { // prototype sprite can't be destroyed, but can 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()
}
}

Ideally, there should be no noticeable differences for game developers, but this is not the case. For example, consider this sprite code:

onStart => {
	for {
		wait 0.1
		println "im alive"
	}
}

onStart => {
	wait 1
	die
}

After calling die, the loop continues, so "im alive" keeps being printed.

In contrast, for a cloned sprite:

onCloned => {
	for {
		wait 0.1
		println "im alive"
	}
}

onCloned => {
	wait 1
	die
}

onStart => {
	clone
}

After calling die, the loop stops, and "im alive" is no longer printed.

Game developers may perform more complex actions than just println "im alive", potentially affecting overall game behavior. Therefore, it is crucial to unify the behavior of die for both sprite types.

Please check this out, @xushiwei @JiepengTan.

@nighca
Copy link
Collaborator Author

nighca commented Aug 26, 2024

Based on the comment here

In Scratch and SPX, the initial instance of a sprite is the prototype (somewhat similar to JavaScript). The prototype instance cannot be destroyed, so the 'die' function behaves differently for prototype instances and cloned instances.

@xushiwei To address compatibility concerns, I suggest:

  • Rename current destroy to deleteThisClone for compatibility with Scratch's Delete This Clone
  • Introduce new destroy, which always destroys the current instance, regardless of whether it's the initial or a cloned instance
  • Implement die based on destroy, so it always destroys the current instance as well

xushiwei added a commit that referenced this issue Sep 11, 2024
fix: Unify Die behavior of initial / cloned sprite #314
@nighca
Copy link
Collaborator Author

nighca commented Sep 12, 2024

closed by #329

@nighca nighca closed this as completed Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant