gpt4 book ai didi

java - Libgdx - TextureAtlas 停止了我的应用程序

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

我正在从扩展 libgdx 类游戏的主游戏类加载 Assets 。在该类的 create() 方法中,我调用了 Assets.loadAtlas(); 并调用了:

public static void loadAtlas() {
String textureFile = "data/rubenSprite.txt";
myTextures = new TextureAtlas(Gdx.files.internal(textureFile));

TextureRegion[] walkRightFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
walkRightFrames[i] = myTextures.findRegion("wframe" + (i + 1));
}
rubenWalkRight = new Animation(0.2f, walkRightFrames[0], walkRightFrames[1],
walkRightFrames[2], walkRightFrames[3], walkRightFrames[4]);

TextureRegion[] walkLeftFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
walkLeftFrames[i] = new TextureRegion(walkRightFrames[i]);
walkLeftFrames[i].flip(true,false);

}
rubenWalkLeft = new Animation(0.2f, walkLeftFrames[0], walkLeftFrames[1],
walkLeftFrames[2], walkLeftFrames[3], walkLeftFrames[4]);

TextureRegion[] idleRightFrames = new TextureRegion[3];
for (int i = 0; i < 4; i ++)
{
idleRightFrames[i] = myTextures.findRegion("iframe" + (i + 1));

}
rubenIdleRight = new Animation(0.2f, idleRightFrames[0], idleRightFrames[1],
idleRightFrames[2], idleRightFrames[3]);

TextureRegion[] idleLeftFrames = new TextureRegion[3];
for (int i = 0; i < 4; i++)
{
idleLeftFrames[i] = new TextureRegion(idleRightFrames[i]);
idleLeftFrames[i].flip(true,false);
}
rubenIdleLeft = new Animation(0.2f, idleLeftFrames[0], idleLeftFrames[1],
idleLeftFrames[2], idleLeftFrames[3]);

TextureRegion[] jumpRightFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
jumpRightFrames[i] = myTextures.findRegion("jframe" + (i + 1));
}

rubenJumpRight = new Animation(0.2f, jumpRightFrames[0], jumpRightFrames[1],
jumpRightFrames[2], jumpRightFrames[3], jumpRightFrames[4]);


TextureRegion[] jumpLeftFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
jumpLeftFrames[i] = new TextureRegion(jumpRightFrames[i]);
jumpLeftFrames[i].flip(true,false);
}
rubenJumpLeft = new Animation(0.2f, jumpLeftFrames[0], jumpLeftFrames[1],
jumpLeftFrames[2], jumpLeftFrames[3], jumpLeftFrames[4]);

TextureRegion fallRight = new TextureRegion();
fallRight = myTextures.findRegion("fall");
rubenFallRight = new Animation(0f, fallRight);

TextureRegion fallLeft = new TextureRegion(fallRight); ;
fallLeft.flip(true,false);
rubenFallLeft = new Animation(0f, fallLeft);
}

从我看过的教程来看,这对我来说似乎是正确的。我已经给出了播放器状态,并根据播放器所处的状态在 mainRenderer 中绘制了其中的动画。这段代码看起来也不错:

private void renderRuben () {
TextureRegion keyFrame;
switch (world.ruben.getState()) {
case Ruben.RUBEN_STATE_HIT:
keyFrame = Assets.bobHit;
break;
case Ruben.RUBEN_STATE_WALKING:
if (Ruben.facingRight == true)
{
keyFrame = Assets.rubenWalkRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
else
{
keyFrame = Assets.rubenWalkLeft.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
case Ruben.RUBEN_STATE_FALL:
if (Ruben.facingRight == true) {
keyFrame = Assets.rubenFallRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
else {
keyFrame = Assets.rubenFallLeft.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
case Ruben.RUBEN_STATE_JUMP:
if (Ruben.facingRight == true) {
keyFrame = Assets.rubenJumpRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
else {
keyFrame = Assets.rubenJumpRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
case Ruben.RUBEN_STATE_IDLE:
default:
if (Ruben.facingRight == true) {
keyFrame = Assets.rubenIdleRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_LOOPING);
}
else {
keyFrame = Assets.rubenIdleRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_LOOPING);
}
}


float side = world.ruben.getVelocity().x < 0 ? -1 : 1;
if (side < 0)
batch.draw(keyFrame, world.ruben.position.x + 0.5f, world.ruben.position.y - 0.5f, side * Ruben.RUBEN_WIDTH, Ruben.RUBEN_HEIGHT);
else
batch.draw(keyFrame, world.ruben.position.x - 0.5f, world.ruben.position.y - 0.5f, side * Ruben.RUBEN_WIDTH, Ruben.RUBEN_HEIGHT);
}

我使用 TexturePacker GUI 打包了 Atlases,并将 png 和 txt 文件保存到/assets/data 文件夹中。

整个项目没有错误,只是在模拟器中打开时显示“应用程序未响应”。我做错了什么?

游戏类的创建方法:

public class GameView extends Game {
// used by all screens
public SpriteBatch batcher;
@Override
public void create () {
batcher = new SpriteBatch();
Settings.load();
Assets.loadAtlas();
setScreen(new MainMenuScreen(this));
}
}

最佳答案

总的来说,这与模拟器有关,而不是应用程序,模拟器与 Open GL ES 2.0 不兼容,所以我下载了 GenyMotion,现在它工作正常。

http://www.genymobile.com/en/

关于java - Libgdx - TextureAtlas 停止了我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29615189/

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