-
Hi, What we have now: var myActor = Group()
myActor.setPosition(4f,5f)
myActor.setSize(5f,5f) I have an extension: fun Actor.lSetSize(width: Float, height: Float): Actor
{
this.setSize(width, height)
return this
}
fun Actor.lSetPosition(x: Float, y: Float, align: Int): Actor
{
this.setPosition(x, y, align)
return this
} which changes that to var myActor = Group()
myActor
.lSetPosition(5f,4f)
.lSetSize(5f,5f) Problem is, this extension always returns objects of class Actor, not of the inheriting class. Any ideas? And would you consider ding something similar in libKTX? Or, alternatively, would it be possible to have more Actor-inheriting classes to be defined at top level like tables? image {
drawable=pathToDrawable
position = Vec2(3f,5f)
...
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
You can use generics fun <T : Actor> T.lSetSize(width: Float, height: Float): T {
this.setSize(width, height)
return this
} However, I would personnally not create such extensions, and use var myActor = Group().apply {
setPosition(5f,4f)
setSize(5f,4f)
}
I may be wrong, but I have the impression that it is already provided by the ktx-scene2d module. |
Beta Was this translation helpful? Give feedback.
-
I advise against writing custom
Does this solve your problem? |
Beta Was this translation helpful? Give feedback.
-
Yeah, thank you. I'm still new to kotlin and didn't know about apply. Thank you for your help. You can close, if you like :) |
Beta Was this translation helpful? Give feedback.
You can use generics
However, I would personnally not create such extensions, and use
apply
instead:I may be wrong, but I have the impression that it is already provided by the ktx-scene2d module.