我现在尝试以三种不同的方式在libGDX中设置延迟。
首先,我尝试使用Timer,但是如果我重新启动活动,计时器将不会再次启动。使用时这是一个已知问题GestureDetector:https : //github.com/libgdx/libgdx/issues/2274
然后,我尝试Gdx.graphics.getDeltaTime在我的render方法中使用设置计时器,但这对我不起作用,因为我将其设置为非连续渲染。答案2中所述在libgdx游戏中设置了延迟
最终,我尝试使用while循环System.getCurrentTimeMilliseconds,但在while循环循环时,这阻止了应用程序识别抽头。
我也听说过DelayAction,但是如何将其实现到代码中呢?https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/actions/DelayAction.html
还有其他设置延迟的方法吗?一个如何实现DelayAction?或者,如何解决TimerlibGDX中的错误?
此问题显示如何为Android视图动画设置侦听器,但它不适用于属性动画.
如何使用属性动画实现相同的功能?
我的动画:
ViewPropertyAnimator viewPropertyAnimator = layout.animate().y(integer).setInterpolator(interpolator).setStartDelay(delay).setDuration(duration);
Run Code Online (Sandbox Code Playgroud) 我知道关于这个话题还有很多其他问题,但是我已经仔细研究了所有这些问题,但仍然没有让它发挥作用.
我已经为测试制作了这段代码:
public class MainActivity extends Activity {
RelativeLayout layout;
TextView widthtext;
TextView heighttext;
int width;
int height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (RelativeLayout) findViewById(R.id.rela);
widthtext = (TextView) findViewById(R.id.textView);
heighttext = (TextView) findViewById(R.id.textView2);
layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
width = layout.getWidth();
height = layout.getHeight();
}
});
widthtext.setText(width);
heighttext.setText(height);
}
Run Code Online (Sandbox Code Playgroud)
和
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:id="@+id/rela">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="123"
android:id="@+id/textView"
android:layout_alignTop="@+id/textView2"
android:layout_toLeftOf="@+id/textView2"
android:layout_toStartOf="@+id/textView2"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp" …Run Code Online (Sandbox Code Playgroud)