我试图加载一个tmx文件到我的2D android游戏,但我得到的只是一个黑色的屏幕。我甚至没有任何错误需要调试,我不知道哪里出错了。这里是我的活动
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>我正在使用最后一个版本的and andengine GLS2,并正在开发一个平板电脑(zync 930+)。
发布于 2015-11-27 11:41:42
我禁用了背景,并将sceneChildren设置为不可见,黑色屏幕消失了。
@Override
public Scene onCreateScene() {
final Scene scene = new Scene();
this.tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);
scene.setChildrenVisible(false);
scene.setBackgroundEnabled(false);
tmxLayer.setScale(0.5f) ;
scene.attachChild(tmxLayer) ;
return scene;
} 但我仍然没有得到我应该拥有的。下面是一个捕获:

当我试图加载我的菜单场景背景时,我已经遇到了这个问题,但是缩放背景精灵修复了它。我不知道在这种情况下该怎么做,我的tmxLayer在被连接到现场之前已经被缩放了!!
https://stackoverflow.com/questions/33955076
复制相似问题