builder icon indicating copy to clipboard operation
builder copied to clipboard

Logic extracting for different sprites

Open nighca opened this issue 2 months ago • 1 comments

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.

nighca avatar Oct 20 '25 08:10 nighca

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()
}

nighca avatar Nov 03 '25 01:11 nighca