gpt4 book ai didi

java - libGDX 中的计时器错误

转载 作者:行者123 更新时间:2023-12-01 11:37:13 25 4
gpt4 key购买 nike

我在计时器中的new Task () 遇到问题。编译器仍然在new Task()处发现错误

Error:(52, 28) error: cannot find symbol class Task

我不知道为什么会发生这种情况。

我在 Android Studio 中编程。

这是我的代码:

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Timer;

public class flashgame extends ApplicationAdapter {
SpriteBatch batch;
Texture logo;
Timer ti;
BitmapFont font;
int sch;
int scw;
String sc_he;
String sc_wi;
int imgh;
int imgw;

@Override
public void create () {
batch = new SpriteBatch();
sch = Gdx.graphics.getHeight();
sc_he = sch+"";
scw = Gdx.graphics.getWidth();
sc_wi = scw+"";
logo = new Texture(Gdx.files.internal("logo.png"));
imgsize(logo);
font = new BitmapFont();
font.setColor(Color.RED);
}

@Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

Timer.schedule(new Task() {
@Override
public void run() {
batch.begin();
batch.setColor(0, 0, 0, 1);
batch.draw(logo, scw / 2 - imgw / 2, sch / 2 - imgh / 2);
batch.end();
}
}, 1.0 / 60.0);
}

public void imgsize (Texture id) {
imgh = id.getHeight();
imgw = id.getWidth();
}
}

最佳答案

AIDE 中出现一些错误,行中:

Timer.schedule(new Timer.Task() { ... }, 1.0 / 60.0);

1.0/60.0 返回 double,但构造函数等待 float。这对我有用:

Timer.schedule(new Timer.Task() { ... }, 1.0f / 60.0f );

关于java - libGDX 中的计时器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29854825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com