在 LibGDX 中完成其中一个动作后,更改序列动作中子对象(同时调用)的属性
Changing properties of child objects(called at the same time) in a sequence action after one of actions has been completed in LibGDX
系统的想法是,当用户单击纹理时,它会移动到 ImageButton
图标。
我有一个方法transitionTextureToActor()
。
如果用户单击纹理,将调用此方法。
此方法仅更改 Image
的属性,因此此 Image
将复制纹理并将其移动到 ImageButton
的图标。移动和调整大小的动作完成后,Image
应该变得不可见。
private void transitionTextureToActor(ShapeProcessor shapeProcessor, Image icon) {
tempActor = shapeProcessor.getAnimatedImage();
tempActor.setSize(shapeProcessor.getWidth(), shapeProcessor.getHeight());
tempActor.setPosition(shapeProcessor.getX(), shapeProcessor.getY());
tempActor.setVisible(true);
shapeProcessor.setVisible(false);
tempActor.addAction(
sequence(
parallel(
sizeTo(icon.getDrawable().getMinWidth(), icon.getDrawable().getMinHeight(), .3F),
moveTo(icon.getX(), icon.getY(), .3f)
),
run(new Runnable() {
@Override
public void run() {
tempActor.setVisible(false);
}
})
)
);
}
因此它适用于单次调用 transitionTextureToActor
方法。
调整大小和移动后图像消失。
但是当我同时调用ShapeProcessor
的多个对象时,只有第一个消失了。
for(ShapeProcessor shape: shapes){
transitionTextureToActor(shape);
}
我想让他们都看不见。 RunnableAction
肯定有问题,因为那里图像变得不可见,但我不知道是什么。
那是因为当时调用了RunnableActions
的run()
个方法,它们都指向同一个对象,被tempActor
引用。尝试创建本地引用并将它们传递给 RunnableActions
:
private void transitionTextureToActor(ShapeProcessor shapeProcessor, Image iconClicked) {
tempActor = shapeProcessor.getAnimatedImage();
tempActor.setSize(shapeProcessor.getWidth(), shapeProcessor.getHeight());
tempActor.setPosition(shapeProcessor.getX(), shapeProcessor.getY());
tempActor.setVisible(true);
shapeProcessor.setVisible(false);
final Actor localReference = tempActor;
tempActor.addAction(
sequence(
parallel(
sizeTo(iconClicked.getDrawable().getMinWidth(), iconClicked.getDrawable().getMinHeight(), .3F),
moveTo(iconClicked.getX(), iconClicked.getY(), .3f)
),
run(new Runnable() {
@Override
public void run() {
localReference.setVisible(false);
}
})
)
);
}
系统的想法是,当用户单击纹理时,它会移动到 ImageButton
图标。
我有一个方法transitionTextureToActor()
。
如果用户单击纹理,将调用此方法。
此方法仅更改 Image
的属性,因此此 Image
将复制纹理并将其移动到 ImageButton
的图标。移动和调整大小的动作完成后,Image
应该变得不可见。
private void transitionTextureToActor(ShapeProcessor shapeProcessor, Image icon) {
tempActor = shapeProcessor.getAnimatedImage();
tempActor.setSize(shapeProcessor.getWidth(), shapeProcessor.getHeight());
tempActor.setPosition(shapeProcessor.getX(), shapeProcessor.getY());
tempActor.setVisible(true);
shapeProcessor.setVisible(false);
tempActor.addAction(
sequence(
parallel(
sizeTo(icon.getDrawable().getMinWidth(), icon.getDrawable().getMinHeight(), .3F),
moveTo(icon.getX(), icon.getY(), .3f)
),
run(new Runnable() {
@Override
public void run() {
tempActor.setVisible(false);
}
})
)
);
}
因此它适用于单次调用 transitionTextureToActor
方法。
调整大小和移动后图像消失。
但是当我同时调用ShapeProcessor
的多个对象时,只有第一个消失了。
for(ShapeProcessor shape: shapes){
transitionTextureToActor(shape);
}
我想让他们都看不见。 RunnableAction
肯定有问题,因为那里图像变得不可见,但我不知道是什么。
那是因为当时调用了RunnableActions
的run()
个方法,它们都指向同一个对象,被tempActor
引用。尝试创建本地引用并将它们传递给 RunnableActions
:
private void transitionTextureToActor(ShapeProcessor shapeProcessor, Image iconClicked) {
tempActor = shapeProcessor.getAnimatedImage();
tempActor.setSize(shapeProcessor.getWidth(), shapeProcessor.getHeight());
tempActor.setPosition(shapeProcessor.getX(), shapeProcessor.getY());
tempActor.setVisible(true);
shapeProcessor.setVisible(false);
final Actor localReference = tempActor;
tempActor.addAction(
sequence(
parallel(
sizeTo(iconClicked.getDrawable().getMinWidth(), iconClicked.getDrawable().getMinHeight(), .3F),
moveTo(iconClicked.getX(), iconClicked.getY(), .3f)
),
run(new Runnable() {
@Override
public void run() {
localReference.setVisible(false);
}
})
)
);
}