TMX image files

  ... discussions about development with the GLES1 branch of AndEngine.

TMX image files

Postby Kalagaraz » Mon Jul 26, 2010 9:41 pm

Where do I put the tilemaps used by TMX? The TMX map file is only a few hundred bytes so i'm pretty sure it doesn't contain the graphics itself.
Kalagaraz
 
Posts: 58
Joined: Tue Jul 20, 2010 4:46 pm

Re: TMX image files

Postby Mimminito » Mon Jul 26, 2010 9:50 pm

Check out the TMX Tile Map examples for AndEngine. It should show you where the assets are loaded from, and you can also check where they have been stored. If you cannot do this ill try and post up later where I think they are.
---------------------------------------
Adam Goodchild
Your AndEngine Forum Moderator!
My Tutorials List
http://www.adam-goodchild.co.uk
---------------------------------------
Mimminito
 
Posts: 360
Joined: Wed Jul 21, 2010 3:08 pm
Location: Chelsmford, UK

Re: TMX image files

Postby Nicolas Gramlich » Mon Jul 26, 2010 10:25 pm

This is the TMX file used in the AndEngineExamples:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE map SYSTEM "http://mapeditor.org/dtd/1.0/map.dtd">
  3. <map version="1.0" orientation="orthogonal" width="40" height="40" tilewidth="32" tileheight="32">
  4.  <tileset firstgid="1" name="Desert" tilewidth="32" tileheight="32" spacing="1" margin="1">
  5.   <image source="gfx/desert_tiled.png"/>
  6.  </tileset>
  7.  <layer name="Ground" width="40" height="40">
  8.   <data encoding="base64" compression="gzip">
  9.    H4sIAAAAAAAAA+2Y2QrCMBBFo31wA+sCrlirdd/q/3+dIzZUhtAmMRlH6cPBBlJyvDO2g5EQIvJIFwiBnudzbLgp/JYMvH4lv2dWI2AMTBj4qKgBdSBA3j7OmgIzA+ZAC2gDHYIsVsDagMSj36HAbwOcgO0X/YrySzTzpPDbMfS7Iy/sdxGv/r8S++Gew+uyvHBfuvBT/Q4OKD95XeaHc3WV3x6tpY9pfr7riz0xx6x+upwd+DUymiJ/FxURaO6TLD70C0U+X8jvWkRHc5/qPhu/scjniz4wKGGouU91n8/eoyYW6jmHk2dM6GMzm1F43bJPnWfn+/sncXS+Ljp+T6d7tpfSL2Xoh/uam59Nfd/nCyq/1MAPZ8ktP1WtOftR5mczm1H6/QsxA4dfAWfF7b/BqsYVFZ/xABSXR5cAGQAA
  10.   </data>
  11.  </layer>
  12. </map>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

The path to store the tileset-image is always relative to "YOUR_APP/assets/" so in our case the file is http://andengineexamples.googlecode.com/hg/assets/gfx/desert_tiled.png
Image

Hope this helped :)

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: TMX image files

Postby Kalagaraz » Tue Jul 27, 2010 2:22 am

ok I correct the image locations in the TMX map file, and game still crashes on launch. I'm not getting any errors in log though. Is there any issue in the TMX loading code with loading more than 1 tileset as mine does...?

Here's my code, probably a simple user error on my part:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.dragontail.touchmarbles;
  2. import android.util.Log;
  3. import java.io.IOException;
  4.  
  5. import org.anddev.andengine.engine.Engine;
  6. import org.anddev.andengine.engine.camera.Camera;
  7. import org.anddev.andengine.engine.options.EngineOptions;
  8. import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
  9. import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  10. import org.anddev.andengine.entity.layer.tiled.tmx.TMXLoader;
  11. import org.anddev.andengine.entity.layer.tiled.tmx.TMXTiledMap;
  12. import org.anddev.andengine.entity.scene.Scene;
  13. import org.anddev.andengine.entity.scene.background.ColorBackground;
  14. import org.anddev.andengine.entity.util.FPSLogger;
  15. import org.anddev.andengine.ui.activity.BaseGameActivity;
  16. import org.anddev.andengine.util.Debug;
  17.  
  18. import android.app.Activity;
  19. import android.os.Bundle;
  20.  
  21. public class TouchMarbles extends BaseGameActivity {
  22.  
  23.         private static final int CAMERA_WIDTH = 768;
  24.         private static final int CAMERA_HEIGHT = 480;
  25.        
  26.         private Camera mCamera;
  27.         private TMXTiledMap mTMXTiledMap;
  28.        
  29.         @Override
  30.         public Engine onLoadEngine() {
  31.                 this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  32.                 return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
  33.         }
  34.  
  35.         @Override
  36.         public void onLoadResources() {
  37.                 try {
  38.                         this.mTMXTiledMap = new TMXLoader(this, this.mEngine.getTextureManager()).load(this.getAssets().open("maps/testMap.tmx"));
  39.                 } catch (final IOException e) {
  40.                         Debug.e(e);
  41.                 }
  42.                
  43.                
  44.         }
  45.  
  46.         @Override
  47.         public Scene onLoadScene() {
  48.                 this.mEngine.registerPreFrameHandler(new FPSLogger());
  49.  
  50.                 final Scene scene = new Scene(1);
  51.                 scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
  52.                 scene.getBottomLayer().addEntity(this.mTMXTiledMap.getTMXLayers().get(0));
  53.                
  54.                 return scene;
  55.         }
  56.  
  57.         @Override
  58.         public void onLoadComplete() {
  59.                 // TODO Auto-generated method stub
  60.                
  61.         }
  62. }
  63.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


the TMX map
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <map version="1.0" orientation="orthogonal" width="24" height="15" tilewidth="32" tileheight="32">
  3.  <tileset firstgid="1" name="floor" tilewidth="32" tileheight="32">
  4.   <image source="gfx/floor.png"/>
  5.  </tileset>
  6.  <tileset firstgid="2" name="wall" tilewidth="32" tileheight="32">
  7.   <image source="gfx/wall.png"/>
  8.  </tileset>
  9.  <layer name="Tile Layer 1" width="24" height="15">
  10.   <data encoding="base64" compression="gzip">
  11.    H4sIAAAAAAAAC2NiYGBgojFmpBEeLOaT629S1BEjhi5OC/Np7f7Baj4t45dcPFDmk2MnLnOGQ/jQEgMASd2F0qAFAAA=
  12.   </data>
  13.  </layer>
  14. </map>
  15.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


I did find some errors in log under AndroidRuntime:


07-26 19:36:08.928: ERROR/AndroidRuntime(22812): Uncaught handler: thread main exiting due to uncaught exception
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.dragontail.touchmarbles/org.dragontail.touchmarbles.TouchMarbles}: java.lang.ArrayIndexOutOfBoundsException
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2558)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2574)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.ActivityThread.access$2400(ActivityThread.java:121)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1925)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.os.Looper.loop(Looper.java:130)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.ActivityThread.main(ActivityThread.java:4425)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at java.lang.reflect.Method.invokeNative(Native Method)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at java.lang.reflect.Method.invoke(Method.java:521)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at dalvik.system.NativeStart.main(Native Method)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): Caused by: java.lang.ArrayIndexOutOfBoundsException
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.anddev.andengine.entity.layer.tiled.tmx.TMXLayer.initializeTextureRegions(TMXLayer.java:181)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.anddev.andengine.entity.layer.tiled.tmx.TMXParser.endElement(TMXParser.java:112)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:159)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.apache.harmony.xml.ExpatParser.append(Native Method)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.anddev.andengine.entity.layer.tiled.tmx.TMXLoader.load(TMXLoader.java:64)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.dragontail.touchmarbles.TouchMarbles.onLoadResources(TouchMarbles.java:38)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at org.anddev.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:55)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-26 19:36:08.928: ERROR/AndroidRuntime(22812): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
Kalagaraz
 
Posts: 58
Joined: Tue Jul 20, 2010 4:46 pm

Re: TMX image files

Postby Kalagaraz » Tue Jul 27, 2010 3:17 am

Nevermind I fixed it. Was a problem in andengine with loading maps.
Kalagaraz
 
Posts: 58
Joined: Tue Jul 20, 2010 4:46 pm

Re: TMX image files

Postby Nicolas Gramlich » Tue Jul 27, 2010 9:56 am

If it was a problem in AndEngine, let us know what it was so I can fix it ;)

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: TMX image files

Postby Kalagaraz » Tue Jul 27, 2010 4:58 pm

Nicolas Gramlich wrote:If it was a problem in AndEngine, let us know what it was so I can fix it ;)

Best Regards,
Nicolas


You already fixed it in another thread, loading non-square maps :)
Kalagaraz
 
Posts: 58
Joined: Tue Jul 20, 2010 4:46 pm


Return to GLES1

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests