在按钮LibGdx上使用操作
我有一个这样的播放按钮在按钮LibGdx上使用操作,libgdx,Libgdx,我有一个这样的播放按钮 private void drawPlayButton() { playButton = new ImageButton(new TextureRegionDrawable(playTexture), new TextureRegionDrawable(pressTexture)); stage.addActor(playButton); playButton.setPosition(UIConstants.PLA
private void drawPlayButton() {
playButton = new ImageButton(new TextureRegionDrawable(playTexture), new TextureRegionDrawable(pressTexture));
stage.addActor(playButton);
playButton.setPosition(UIConstants.PLAY_X, UIConstants.PLAY_Y, Align.center);
playButton.addListener(new ActorGestureListener() {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
game.setScreen(new GameScreen(game));
}
});
}
float duationsec= 0.5f;
playButton.addAction(Actions.sequence(Actions.scaleBy(0.2f,0.2f,duationsec),
Actions.scaleTo(1f, 1f, duationsec)));
img.setOrigin(Align.center);
stage.addActor(playButton);
我想使用动作将缩放效果添加到此按钮
我对动作不太熟悉,我试过这样的动作
private void drawPlayButton() {
playButton = new ImageButton(new TextureRegionDrawable(playTexture), new TextureRegionDrawable(pressTexture));
stage.addActor(playButton);
playButton.setPosition(UIConstants.PLAY_X, UIConstants.PLAY_Y, Align.center);
playButton.addListener(new ActorGestureListener() {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
game.setScreen(new GameScreen(game));
}
});
}
float duationsec= 0.5f;
playButton.addAction(Actions.sequence(Actions.scaleBy(0.2f,0.2f,duationsec),
Actions.scaleTo(1f, 1f, duationsec)));
img.setOrigin(Align.center);
stage.addActor(playButton);
但这并没有给按钮带来任何效果,同样的代码也适用于图像。这是因为按钮使用了可绘制的纹理吗
我如何使用动作赋予按钮这种效果
另外,我的代码只工作一次。我在show()中调用它。如果我在render()中调用它,它将以异常方式工作。我希望此效果永远显示
有可能做到这一点吗?
任何帮助都将不胜感激。出于性能原因,大多数
scene2d.ui
组的transform
默认设置为false,并且ImageButton
是该ui组的一部分,因此您必须使用setTransform(…)
方法启用转换
有关更多详细信息,请查看启用转换后也没有效果。您想在
playButton
上的什么位置应用操作?我希望该效果永远显示在按钮上。我引用了这个问题并使其生效。[.使用容器后,它工作了。此链接包含类似的问题和答案。