nicolasgramlich / AndEngine

Free Android 2D OpenGL Game Engine
http://www.andengine.org
Apache License 2.0
3.17k stars 1.35k forks source link

Load a .tmx map and display inside a layout ? #290

Open MayeuldP opened 7 years ago

MayeuldP commented 7 years ago

I'm trying to display a .tmx map that I did with Tiled Map Editor. I want to display it inside a layout (Android Mobile Application), however I didn't find any tips or tutoriel about how to do it, and I have absolutely no ideas. I did all the references to AndEngine, and my environement is correctly setup. I just need a link or infos about how to do that. I tried this simple piece of code :

 public class YourActivity extends SimpleBaseGameActivity {
     private TMXTiledMap tiledMap;
     private TMXLayer tmxLayer;

     @Override
     protected void onCreateResources() {
       try {
           final TMXLoader tmxLoader = new TMXLoader(getAssets(), getTextureManager(), TextureOptions.NEAREST, getVertexBufferObjectManager(), new ITMXTilePropertiesListener() {
            @Override
            public void onTMXTileWithPropertiesCreated(final TMXTiledMap tmxTiledMap, final TMXLayer tmxLayer, final TMXTile tmxTile, final TMXProperties<TMXTileProperty> tmxTileProperties) {
                    // do stuff with tiles that have properties...
            }
           });
           this.tiledMap = tmxLoader.loadFromAsset("tmx/yourMap.tmx");
           this.tiledMap.setIsometricDrawMethod(TMXIsometricConstants.DRAW_METHOD_ISOMETRIC_CULLING_PADDING);
       } catch (final TMXLoadException e) {
            Debug.e(e);
       }

     }

     @Override
     protected Scene onCreateScene() {
           this.tmxLayer = this.tiledMap.getTMXLayers().get(0);  // the 0 is just an index of the layer. It depends on how many layers you created within Tiled
           attachChild(this.tmxLayer);
     }

But I got many errors concerning this line new TMXLoader(... so maybe it's deprecated... If you have any ideas, I would be very grateful ! Thank's for your help !