builder
builder copied to clipboard
Logic extracting for different sprites
To improve code reuse, we need a mechanism for extracting common logic from sprites. This becomes challenging when the shared logic relies on a sprite's specific fields or methods.
For instance:
A.spx
var (
count int
)
func increase() {
count++
}
B.spx
var (
count int
)
func increase() {
count++
}
Currently, there's no good way to extract logic dependent on the count field or increase method for A & B.
We may use a standalone (invisible) sprite to extract common logic & use embedding to share it:
Common.spx:
var (
count int
)
func increase() {
count++
}
A.spx / B.spx:
var (
Common
)
onStart => {
increase()
}