如何使用AndEngine加载TMX

时间:2012-11-04 19:27:42

标签: android andengine tmx

我刚刚遇到TMX和AndEngine的问题,我用mapeditor创建了一个tmx文件然后加载到我的游戏中,我得到了这个:

11-05 02:07:43.656: E/AndEngine(1482): GameScreen.onCreateScene failed. @(Thread: 'GLThread 70')
11-05 02:07:43.656: E/AndEngine(1482): java.lang.NullPointerException
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.extension.tmx.TMXLayer.addTileByGlobalTileID(TMXLayer.java:277)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.extension.tmx.TMXLayer.initializeTMXTilesFromDataString(TMXLayer.java:247)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.extension.tmx.TMXParser.endElement(TMXParser.java:197)
11-05 02:07:43.656: E/AndEngine(1482):  at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:156)
11-05 02:07:43.656: E/AndEngine(1482):  at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
11-05 02:07:43.656: E/AndEngine(1482):  at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:513)
11-05 02:07:43.656: E/AndEngine(1482):  at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
11-05 02:07:43.656: E/AndEngine(1482):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
11-05 02:07:43.656: E/AndEngine(1482):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.extension.tmx.TMXLoader.load(TMXLoader.java:117)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.extension.tmx.TMXLoader.loadFromAsset(TMXLoader.java:102)
11-05 02:07:43.656: E/AndEngine(1482):  at com.zk.tank.GameScreen.onCreateScene(GameScreen.java:51)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateScene(SimpleBaseGameActivity.java:48)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.ui.activity.BaseGameActivity$3.onCreateResourcesFinished(BaseGameActivity.java:169)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:43)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
11-05 02:07:43.656: E/AndEngine(1482):  at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
11-05 02:07:43.656: E/AndEngine(1482):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
11-05 02:07:43.656: E/AndEngine(1482):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

这里是我的tmx文件,我该怎么办呢,谢谢大家,抱歉我的英文不好

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="20" height="15" tilewidth="32" tileheight="32">
 <properties>
  <property name="level" value="1"/>
 </properties>
 <tileset firstgid="1" name="tank_tile_set" tilewidth="32" tileheight="32">
  <image source="tilesets/tank_tile_set.png" width="1024" height="1024"/>
  <tile id="30">
   <properties>
    <property name="type" value="ALL"/>
   </properties>
  </tile>
 </tileset>
 <layer name="background" width="20" height="15">
  <data encoding="base64" compression="gzip">
   H4sIAAAAAAAAA5XSSS9DURTA8ds2aZuI+RMgQSLmT4AEG0PwBZCYV/gCSAyttjaGrZZW0NbGsNXSmraGLRLz9BH8b6rp69VXkbxf3j3vnnNyT951G4TwYA3rKBdCVKASVXDACRcW8I4PfOJLJOq88CGEMI5wjBZyWtGGdvgRQBA7yCQnC9nI0dRFEMUoOWMYxyLxEpaxYkiO9dYyrxo1qIWZPhZYsUu8h30cGJJjvbXM4xFGmFCMEpTi8o9z6K0LqC1EERrRhOYU86rn0O5pv9dRW48G9KEfA8q8src87xWucfPTJ95D+72b2h70YhozmBXJ9elmVfcmqJ3EFLzwYUOZV51V7z/JeJVaNzyIIIoTZV51Vu1a3TukNoQwHvCIpzTzpruXMr6l9g73MBNbYP3Hfft1/2CECR307ESXcj69dap5c5GHfNhgxzwcGKbvCE5xhnNciNh+Bu9BDIlEXrzOCRc2sYVt+GVvmYNnvOAVbyK2X8Z7DjaRyIvXBRDEN9foDnOwBAAA
  </data>
 </layer>
 <layer name="rock" width="20" height="15">
  <properties>
   <property name="type" value="ROCK"/>
  </properties>
  <data encoding="base64" compression="gzip">
   H4sIAAAAAAAAA5vNyMAwe4jjP0iY2uZiswef/cS6g5ruHaxm0cIthOIAX3zgM49YewYbplZaIzX9EmsntcyEmQEAk0W7NbAEAAA=
  </data>
 </layer>
 <layer name="bush" width="20" height="15">
  <properties>
   <property name="type" value="B"/>
  </properties>
  <data encoding="base64" compression="gzip">
   H4sIAAAAAAAAA5vNyMAwexRj4Fgm6ppXCzQvjgwzY3HoA5lXR6J5ILNqcegh1Tx8ZiGbB3I7Lj8QaxY295Ebnvj8i81MmDp0mlJ7a6lgFrKZ1DIL2UxqmUVNDABjR6L7sAQAAA==
  </data>
 </layer>
 <layer name="wonder" width="20" height="15">
  <properties>
   <property name="type" value="WONDER"/>
  </properties>
  <data encoding="base64" compression="gzip">
   H4sIAAAAAAAAA5vNyMAwexSP4lE8ionEpcwMDGXM1DNvKtCsaUSaBwBrtIRdsAQAAA==
  </data>
 </layer>
</map>

0 个答案:

没有答案