First of all, you should use field
instead of sprite
inside your custom getter / setter. Otherwise, the result will be a recursive call.
What you are trying to do does not work as the compiler says. You need to overload setter and add it as a regular method to your class as follows:
setSprite(s : String) { sprite = Sprite(Texture(s)) }
source
share