goplus / spx

spx - A Scratch Compatible Go/Go+ 2D Game Engine for STEM education
https://builder.goplus.org
Apache License 2.0
102 stars 28 forks source link

Unify `Die` behavior of initial / cloned sprite #314

Closed nighca closed 1 month ago

nighca commented 2 months ago

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

https://github.com/goplus/spx/blob/3df776b555a0532999520609e172f45c1816de49/sprite.go#L483-L494

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 commented 2 months ago

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:

nighca commented 1 month ago

closed by #329