Libgdx类不绘制纹理

问题描述 投票:0回答:1

当我触摸手机的屏幕时,我试图从“germans.java”类中的“MainGameScreen.java”类中绘制一个游戏角色。 不幸的是我的程序没有绘制图像,也没有给我一个警告或错误。

main game screen.Java:

import com.daenni.trenchwarfare.mygdx.enteties.germans;

public class MainGameScreen implements Screen, InputProcessor {

Trench_Warfare game;


public SpriteBatch batch;

//Enemies
ArrayList<germans> german;

public MainGameScreen (Trench_Warfare game) {
    this.game = game;
    batch = new SpriteBatch();

    //Enemies
    //Initialise Array
    german = new ArrayList<germans>();
}

@Override
public void render(float delta) {

    //Colours
    Gdx.gl.glClearColor(116/255f,102/255f,91/255f,1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    //Create Germans

    if (Gdx.input.justTouched()){
        german.add(new germans(300));
        german.add(new germans(400));
    }

    //Update Germans
    for (germans german : german) {
        german.update(delta);
    }

    game.batch.begin();


    //Render Germans
    for (germans germans : german) {
        germans.render(game.batch);
    }

    //Background
    game.batch.draw(background,0,0);
    game.batch.draw(background_links,-background_links.getWidth(),0);
    game.batch.draw(background_rechts,background.getWidth(),0);

    game.batch.end();
}

这是我用于在“MainGameScreen.java”文件中呈现它的所有代码。 这是我的班级:

public class germans {
    //Set speed
    public static final int speed = 25;

    //Constant
    public static final int default_x = 300;

    //Every german uses the same Texture
    private static Texture texture;

    //Position
    float x, y;

    public boolean remove = false;

    //Create german
    public germans(float y) {
        this.x = default_x;
        this.y = y;
        y = 200;

        if (texture == null) { //When texture is never loaded
            //Set Texture
            texture = new Texture("de_s1_default.png");
        }
    }

    public void update (float deltaTime){
            x += speed * deltaTime;
    }

    public void render (SpriteBatch batch) {
        batch.draw(texture,x,y);
    }

}
java android libgdx textures draw
1个回答
1
投票

虽然我并不热衷于libgdx究竟是如何工作的,但我很确定首先画出你的“德国人”然后背景不是你想要的。

尝试交换它:

//Background
game.batch.draw(background,0,0);
game.batch.draw(background_links,-background_links.getWidth(),0);
game.batch.draw(background_rechts,background.getWidth(),0);

    //Render Germans
for (germans germans : german) {
    germans.render(game.batch);
}
© www.soinside.com 2019 - 2024. All rights reserved.