我有一个像这样的Letter类:
class Letter : Label {
val char: Char
var interactable = true
constructor(char: Char) : super(""+char, H.letterStyle()) {
this.char = char
}
fun animateSelect() {
addAction(Actions.scaleTo(3.0f, 3.0f, 0.5f))
}
fun animateUnselect() {
addAction(Actions.scaleTo(3.0f, 3.0f, 0.5f))
}
}
在我的触摸监听器中,我有以下内容:
override fun touchDown(event: InputEvent?, x: Float, y: Float, pointer: Int, button: Int): Boolean {
var currentInteractingLetter: Letter? = null
for (letter in letterList) {
if (letter.bound.contains(x, y)) {
currentInteractingLetter = letter
break
}
}
if (currentInteractingLetter == null) {
} else {
selectedLetters.add(currentInteractingLetter)
currentInteractingLetter.animateSelect()
currentInteractingLetter.interactable = false
}
return true
}
逻辑很简单。当用户触摸任一
letter
时,我将调用animateSelect()
函数。当我运行它时,
animateSelect
确实被调用,但是没有scaleUp
效果。我尝试清除addAction
之前的所有操作,但仍然相同。
最佳答案
标签不直接支持缩放。
解决此问题的简单方法是将标签放在Container上的Container和setTransform(true)
中,并将您的scale操作添加到Container
。
val container= Container<Label>().apply {
isTransform=true
actor=label // Set your Label to container
}
container.addAction(Actions.scaleTo(3.0f, 3.0f, 0.5f))
关于libgdx - libGDX无法执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45775477/