3d Libgdx中的卡片翻转动画
如何在Libgdx中实现卡片翻转动画(以一定角度翻转)– 我使用了sprite.flip(布尔x,布尔y),但无法达到预期的效果 我想做类似的事情:3d Libgdx中的卡片翻转动画,3d,libgdx,flip,3d,Libgdx,Flip,如何在Libgdx中实现卡片翻转动画(以一定角度翻转)– 我使用了sprite.flip(布尔x,布尔y),但无法达到预期的效果 我想做类似的事情: 缩小第一张图片的宽度,直到其宽度为零,然后开始增加第二张图片的宽度。例如: public void flip() { if(Graphic1.getWidth() == 0) { Graphic2.setWidth(Graphic2.getWidth()+5); } else {
缩小第一张图片的宽度,直到其宽度为零,然后开始增加第二张图片的宽度。例如:
public void flip() {
if(Graphic1.getWidth() == 0) {
Graphic2.setWidth(Graphic2.getWidth()+5);
} else {
Graphic1.setWidth(Graphic1.getWidth()-5);
}
}
调用render()
方法中的flip()
方法,使用if()
station检测按钮是否已按下。大概是这样的:
@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
boolean ButtonPressed = false;
if(ButtonPressed) {
flip();
}
}
使用按钮的eventHandler激活按钮按下的。将其设置为true
。另外,请确保除非按钮的eventHandler位于render()
方法中,否则将ButtonPressed
设置为任何方法之外的静态变量,仍然位于类内部
public class Demo {
static boolean ButtonPressed = false;
public void onCreate() {
...
如果要创建更酷的效果,请在每次调用flip()
方法时增加宽度收缩的距离,然后在宽度为零后,开始每次减少宽度
希望这有帮助 如果在代码中使用,可以使用我编写的以下两个操作:
public class MyActions {
public static Action flipOut(final float x, final float width, final float duration) {
return new Action() {
float left = duration;
@Override
public boolean act(float delta) {
left -= delta;
if (left <= 0) {
actor.setX(x + (width / 2));
actor.setWidth(0);
return true;
}
float tmpWidth = width * (left / duration);
actor.setX(x + ((width / 2) - (tmpWidth / 2)));
actor.setWidth(tmpWidth);
return false;
}
};
}
public static Action flipIn(final float x, final float width, final float duration) {
return new Action() {
float done = 0;
@Override
public boolean act(float delta) {
done += delta;
if (done >= duration) {
actor.setX(x);
actor.setWidth(width);
return true;
}
float tmpWidth = width * (done / duration);
actor.setX(x + ((width / 2) - (tmpWidth / 2)));
actor.setWidth(tmpWidth);
return false;
}
};
}
}
如果你想让你的卡片有不同的侧面,你必须在中间加一个动作来切换演员的形象
你也可以使用内置的动作,这会导致很多口吃,所以我不推荐:
SequenceAction action = new SequenceAction(
new ParallelAction(
Actions.scaleTo(0, 1, duration),
Actions.moveBy(width / 2, 0, duration)),
new ParallelAction(
Actions.scaleTo(1, 1, duration),
Actions.moveBy(-width / 2, 0, duration)));
在这种情况下,sprite.flip对您没有帮助,您可以创建两个网格平面并沿x轴旋转它们以实现此目的animation@whiteFang谢谢你的答复。。请给我一些参考或链接,帮助我做到这一点(我从来没有使用网格平面)
SequenceAction action = new SequenceAction(
new ParallelAction(
Actions.scaleTo(0, 1, duration),
Actions.moveBy(width / 2, 0, duration)),
new ParallelAction(
Actions.scaleTo(1, 1, duration),
Actions.moveBy(-width / 2, 0, duration)));