Java 我的程序没有';t绘制/渲染必须绘制的内容

Java 我的程序没有';t绘制/渲染必须绘制的内容,java,libgdx,game-engine,Java,Libgdx,Game Engine,我正在读一本关于游戏开发的书:用LibGDX开始Java游戏开发 我从书中复制了一个名为CheesePlease3的类,它呈现了Stage类和Actor类,我必须从Actor类中创建一个子类,名为BaseActor 我做的一切都是正确的,基本上是复制粘贴了整个东西,它没有画任何物体 所以我的问题是为什么?怎么了 也许代码本身有点长,但容易阅读 以下是CheesePlease3课程: public class CheesePlease3 extends Game { public Stage m

我正在读一本关于游戏开发的书:用LibGDX开始Java游戏开发

我从书中复制了一个名为
CheesePlease3
的类,它呈现了
Stage
类和
Actor
类,我必须从
Actor
类中创建一个子类,名为
BaseActor

我做的一切都是正确的,基本上是复制粘贴了整个东西,它没有画任何物体

所以我的问题是为什么?怎么了

也许代码本身有点长,但容易阅读

以下是
CheesePlease3
课程:

public class CheesePlease3 extends Game {

public Stage mainStage;
private BaseActor mouse;
private BaseActor cheese;
private BaseActor floor;
private BaseActor winText;

@Override
public void create () {

    mainStage = new Stage();

    floor = new BaseActor();
    floor.setTexture(new Texture("floor.png"));
    floor.setPosition(0, 0);
    mainStage.addActor(floor);

    cheese = new BaseActor();
    cheese.setTexture(new Texture("cheese.png"));
    cheese.setPosition(300, 300);
    mainStage.addActor(cheese);

    mouse = new BaseActor();
    mouse.setTexture(new Texture("mouse.png"));
    mouse.setPosition(200, 200);
    mainStage.addActor(mouse);

    winText = new BaseActor();
    winText.setTexture(new Texture("youWon.png"));
    winText.setPosition(150, 150);
    winText.setVisible(false);
    mainStage.addActor(winText);

}

@Override
public void render(){
    // process input

    mouse.velocityX = 0;
    mouse.velocityY = 0;

    if (Gdx.input.isKeyPressed(Input.Keys.LEFT))
        mouse.velocityX -= 100;
    if (Gdx.input.isKeyPressed(Input.Keys.RIGHT))
        mouse.velocityX += 100;
    if (Gdx.input.isKeyPressed(Input.Keys.UP))
        mouse.velocityY -= 100;
    if (Gdx.input.isKeyPressed(Input.Keys.DOWN))
        mouse.velocityY += 100;

    // update

    float dt = Gdx.graphics.getDeltaTime();
    mainStage.act(dt);

    // check win condition: Mouse must be overlapping cheese

    Rectangle mouseRectangle = mouse.getBoundingRectangle();
    Rectangle cheeseRectangle = cheese.getBoundingRectangle();

    if (mouseRectangle.contains(cheeseRectangle))
        winText.setVisible(true);

    // draw graphics

    Gdx.gl.glClearColor(0.8f, 0.8f, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


    mainStage.draw();

}
下面是BaseActor类:

public class BaseActor extends Actor {

public TextureRegion region;
public Rectangle boundary;
public float velocityX;
public float velocityY;

public BaseActor(){
    super();
    region = new TextureRegion();
    boundary = new Rectangle();
    velocityX = 0;
    velocityY = 0;
}

public void setTexture (Texture t){
    int w = t.getWidth();
    int h = t.getHeight();
    setWidth(w);
    setHeight(h);
    region.setRegion(t);
}

public Rectangle getBoundingRectangle(){
    return boundary.set(getX(), getY(), getWidth(), getHeight());
}

@Override
public void act (float dt){
    super.act(dt);
    moveBy(velocityX * dt, velocityY * dt);
}

public void drawBatch (Batch batch, float parentAlpha){
    Color c = getColor();
    batch.setColor(c.r, c.g, c.b, c.a);

    if (isVisible())
        batch.draw(region, getX(), getY(), getOriginX(), getOriginY(),
                   getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
这是DesktopLauncher:

public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    new LwjglApplication(new CheesePlease3(), config);
    config.title = "Mouse - Cheese";
}

BaseActor必须重写
draw
方法。
我假设
drabatch
方法应该重命名为
draw

附言:
向上和向下的移动是反向的。

BaseActor必须覆盖
绘制方法。
我假设
drabatch
方法应该重命名为
draw

附言:
向上和向下的移动是反向的。

您的
主机在哪里?代码实际在哪里执行?它在DesktopLauncher类中,与LibGDX提供的相同。我编辑了这个问题,所以它也提供了主要方法。你在那里调用
CheesePlease4
,而不是
CheesePlease3
?是的,这是一个新任务,但这两个任务是一样的,我不想开始一个新任务,直到这个任务起作用为止。你的
main
在哪里?代码实际在哪里执行?它在DesktopLauncher类中,与LibGDX提供的相同。我已经编辑了这个问题,所以它也提供了主要的方法。你在那里调用的是
CheesePlease4
,而不是
CheesePlease3
?是的,这是一个新任务,但这两个都是一样的,我不想开始一个新任务,直到这个任务成功谢谢你。这是拉比奇法,也谢谢你指出了这个动作。真的谢谢你。这是牵引法,也感谢你指出了运动。