gpt4 book ai didi

java - 使用 AndEngine 运行简单代码

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

我最近开始学习 AndEngine,但我在运行它时遇到了麻烦。我正在学习有关基础知识的教程,我想加载一个 png 图像,但它给我错误和项目失败了。

这里是源码

public class MainActivity extends BaseGameActivity {
protected static final int WIDTH = 800;
public static final int HEIGHT = 460;
BitmapTextureAtlas playerTexture;
ITextureRegion playerTexureRegion;
Scene scene;

@Override
public EngineOptions onCreateEngineOptions() {
Camera mCamera = new Camera(0, 0, WIDTH, HEIGHT);
EngineOptions engine = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(WIDTH, HEIGHT), mCamera);

return engine;
// TODO Auto-generated method stub

}

@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
// TODO Auto-generated method stub
loadsfx();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}

private void loadsfx() {
// TODO Auto-generated method stub
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("assets/");

playerTexture = new BitmapTextureAtlas(getTextureManager(),64,64);
playerTexureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(playerTexture, this, "fred1.png",0,0);
playerTexture.load();
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
// TODO Auto-generated method stub
this.scene = new Scene();
this.scene.setBackground(new Background(0,125,58));

pOnCreateSceneCallback.onCreateSceneFinished(this.scene);

}

@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) {
// TODO Auto-generated method stub
return super.onCreateEngine(pEngineOptions);
}

@Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub

Sprite sPlayer = new Sprite(WIDTH / 2, HEIGHT / 2, playerTexureRegion, this.mEngine.getVertexBufferObjectManager());
sPlayer.setRotation(45.0f);
this.scene.attachChild(sPlayer);
pOnPopulateSceneCallback.onPopulateSceneFinished();
}

这是 LogCat 所说的内容

05-20 18:11:28.110: E/AndEngine(6616): at android.content.res.AssetManager.openAsset(Native Method)
05-20 18:11:28.110: E/AndEngine(6616): at android.content.res.AssetManager.open(AssetManager.java:315)
05-20 18:11:28.110: E/AndEngine(6616): at android.content.res.AssetManager.open(AssetManager.java:289)
05-20 18:11:28.110: E/AndEngine(6616): at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:86)
05-20 18:11:28.110: E/AndEngine(6616): at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:154)
05-20 18:11:28.110: E/AndEngine(6616): at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:137)
05-20 18:11:28.110: E/AndEngine(6616): at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:254)
05-20 18:11:28.110: E/AndEngine(6616): at org.andengine.engine.Engine.onDrawFrame(Engine.java:613)
05-20 18:11:28.110: E/AndEngine(6616): at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
05-20 18:11:28.110: E/AndEngine(6616): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
05-20 18:11:28.110: E/AndEngine(6616): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

请帮助我,我非常想了解引擎,但它不起作用。

最佳答案

BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(path);

“setAssetBasePath”从“ Assets ”目录设置 Assets 路径。在您的代码中, Sprite 图像的完整路径必须是“/assets/assets/fred1.png”。如果 Sprite 路径“/assets/fred1.png”只需删除 BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("assets/");

关于java - 使用 AndEngine 运行简单代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16652080/

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