我如何将此 Java 代码转换为 Kotlin libGDX
How Do I Convert This Java Code to Kotlin libGDX
actor.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
System.out.println("Changed!");
}
});
我不知道如何将 ChangeEvent 处理程序代码从 Java 转换为 Kotlin
actor.addListener(object : ChangeListener() {
fun changed(event: ChangeEvent?, actor: Actor?) {
println("Changed!")
}
})
如果使用ktx actors library,就变得很简单了:
actor.onChange {
println("Changed!")
}
或者如果您出于某种原因需要该活动:
actor.onChangeEvent { event ->
println("Changed!")
}
actor.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
System.out.println("Changed!");
}
});
我不知道如何将 ChangeEvent 处理程序代码从 Java 转换为 Kotlin
actor.addListener(object : ChangeListener() {
fun changed(event: ChangeEvent?, actor: Actor?) {
println("Changed!")
}
})
如果使用ktx actors library,就变得很简单了:
actor.onChange {
println("Changed!")
}
或者如果您出于某种原因需要该活动:
actor.onChangeEvent { event ->
println("Changed!")
}