我正在尝试将tmx文件加载到我的2D安卓游戏中,但我得到的只是一个黑屏。我甚至没有任何调试错误。我不知道它出了什么问题。 这是我的活动
package com.example.parkmycar;
import org.andengine.engine.Engine;
import org.andengine.engine.LimitedFPSEngine;
import org.andengine.engine.camera.BoundCamera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.util.FPSLogger;
import org.andengine.extension.tmx.TMXLayer;
import org.andengine.extension.tmx.TMXLoader;
import org.andengine.extension.tmx.TMXTiledMap;
import org.andengine.extension.tmx.util.exception.TMXLoadException;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.ui.activity.SimpleBaseGameActivity;
public class GameActivity extends SimpleBaseGameActivity {
private static final int CAMERA_WIDTH = 550;
private static final int CAMERA_HEIGHT = 300;
private BoundCamera mBoundChaseCamera;
private TMXTiledMap mTMXTiledMap;
protected int mCactusCount;
private TMXLayer tmxLayer;
@Override
public Engine onCreateEngine(EngineOptions engineOptions){
//Creating our customized engine
return new LimitedFPSEngine(engineOptions,60) ;
}
@Override
public EngineOptions onCreateEngineOptions() {
this.mBoundChaseCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mBoundChaseCamera);
}
@Override
protected void onCreateResources() {
final TMXLoader tmxLoader = new TMXLoader(getAssets(), getTextureManager(), TextureOptions.NEAREST, mEngine.getVertexBufferObjectManager());
try {
this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/3afak.tmx");
} catch (TMXLoadException e) {
e.printStackTrace();
System.out.println("Problem in loading the tmx file");
}
}
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
this.tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0); // the 0 is just an index of the layer. It depends on how many layers you created within Tiled
scene.attachChild(tmxLayer) ;
scene.setScale(1.5f);
/* this.mBoundChaseCamera.setBounds(0, 0, tmxLayer.getHeight(), tmxLayer.getWidth());
this.mBoundChaseCamera.setBoundsEnabled(true);
*/
return scene;
}
}
这是我的tmx文件:
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="15" height="15" tilewidth="32" tileheight="32" nextobjectid="1">
<tileset firstgid="1" name="grass" tilewidth="32" tileheight="32" tilecount="36">
<image source="gfx/grass.jpg" width="200" height="200"/>
</tileset>
<layer name="Tile Layer 1" width="15" height="15">
<data encoding="base64" compression="gzip">
H4sIAAAAAAAAC42Q1w7CMBAEYwihhpJQTA3F//+NrKU96WSdDQ8jhTuPd01dVdUUtApHRmAMajABTTJ3PN8Xzlu+Y2bOaYws646cuyrsS7nR6/58u+X5H++2XPEe6q70PTlXvKA6pL1yrnhBdUh7lf4r7Ul3yYyzlv4MzMECLLkPRnfJjLOe/hpswBbsuA/K85xJZpyd6e/BARzBSe2DusOrzDgb6F/AFdzAnfs3+Bi+9H/Rf/Jbn09/i9+RL3n27EWEAwAA
</data>
</layer>
</map>
我正在使用最新版本的andengine GLS2并在平板电脑上工作(zync 930 +)。