gpt4 book ai didi

java - LIBGDX 如何从纹理图集添加 Sprite

转载 作者:行者123 更新时间:2023-11-29 05:43:45 25 4
gpt4 key购买 nike

我需要知道如何从纹理图集中添加一个 sprite,以便我可以将它实现为我的主菜单的 sprite。

这是我的主菜单代码:

public class MainMenu implements Screen {

CrazyZombies game;
Stage stage;
TextureAtlas atlas;
Skin skin;
SpriteBatch batch;

TextureRegion firstLayer;
TextureRegion secondLayer;
TextureRegion thirdLayer;
TextureRegion fourthLayer;
TextureRegion fifthLayer;
TextureRegion sixthLayer;
TextureRegion seventhLayer;
TextureRegion eighthLayer;
TextureRegion ninthLayer;
TextureRegion tenthLayer;
TextureRegion eleventhLayer;

public MainMenu(CrazyZombies game){
this.game = game;
}

@Override
public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1);

batch.begin();
batch.end();
}

@Override
public void resize(int width, int height) {
Gdx.input.setInputProcessor(stage);


}

@Override
public void show() {
batch = new SpriteBatch();
skin = new Skin();
}

@Override
public void hide() {
dispose();
}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {
batch.dispose();
skin.dispose();
atlas.dispose();
stage.dispose();
}

public void loadLayers() {
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/mainmenu/MainMenu.pack"));
firstLayer = atlas.findRegion("1layer");
}
}

所以我需要着手将 firstLayer 放到屏幕上,但我尝试过的每一种方法都以崩溃告终。

最佳答案

你做的不对。您的渲染方法没有任何平局。看看 SuperJumper libgdx 中的演示。

回答如何创建 Sprite -

Sprite mySprite;
...
...
mySprite = new Sprite(someTextureRegion);
mySprite.setSize(SOME_WIDTH, SOME_HEIGHT);
mySprite.setOrigin(SOME_WIDTH/2f, SOME_HEIGHT/2f);
mySprite.setPosition(world.sprite.bounds.x, world.sprite.bounds.y);
...
...
mySprite.draw(batch);

关于java - LIBGDX 如何从纹理图集添加 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550544/

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