libGDX无法执行操作

时间:2017-08-19 19:17:31

标签: libgdx kotlin

我有一个像这样的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之前清除所有操作但仍然相同。

1 个答案:

答案 0 :(得分:1)

标签不直接支持缩放。

解决此问题的简便方法是将标签放在容器上的ContainersetTransform(true),然后将缩放操作添加到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))