0

Just getting started with using tmx tiled maps files as maps for my 2d platformer. This is the code I have so far.

    private void loadLevel() {
    // TODO Auto-generated method stub
    try {
        TMXLoader tmxLoader = new TMXLoader(
                ResourceManager.getInstance().activity.getAssets(),
                engine.getTextureManager(),
                TextureOptions.BILINEAR_PREMULTIPLYALPHA, vbom);

        this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/testmap2.tmx");
    } catch (final TMXLoadException tmxle) {
        Debug.e(tmxle);
    }
    for (int i = 0; i < this.mTMXTiledMap.getTMXLayers().size(); i++) {
        TMXLayer layer = this.mTMXTiledMap.getTMXLayers().get(i);
        this.attachChild(layer);
    }
    for (final TMXObjectGroup group : this.mTMXTiledMap
            .getTMXObjectGroups()) {
        for (final TMXObject object : group.getTMXObjects()) {

            if (group.getName().equals("Unwalkable")) {
                Rectangle rect = new Rectangle(object.getX(),
                        object.getY(), object.getWidth(),
                        object.getHeight(), vbom);

                FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(
                        0.0f, 0.0f, 1f, false,
                        CATEGORYBIT_WALL,
                        MASKBITS_WALL, (short) 0);

                PhysicsFactory.createBoxBody(physicsWorld, rect,
                        BodyType.StaticBody, boxFixtureDef);

                rect.setVisible(false);

                final PhysicsHandler physicsHandler = new PhysicsHandler(
                        rect);
                rect.registerUpdateHandler(physicsHandler);

                attachChild(rect);

            }

        }
    }
}

But it's giving me this error - FATAL EXCEPTION: UpdateThread and java.lang.IllegalArgumenetException: No value found for attribute: 'width'

Is this a problem with my tmx file? How it's encoded or how I set it up? Or is it on the coding end?? Thanks guys I really appreciate the help. Here's the rest of the LogCat in case you have a use for it.

04-25 08:36:01.716: E/AndroidRuntime(13119): FATAL EXCEPTION: UpdateThread
04-25 08:36:01.716: E/AndroidRuntime(13119): java.lang.IllegalArgumentException: No value found for attribute: 'width'
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.util.SAXUtils.getAttributeOrThrow(SAXUtils.java:47)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.util.SAXUtils.getIntAttributeOrThrow(SAXUtils.java:86)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.extension.tmx.TMXObjectGroup.<init>(TMXObjectGroup.java:37)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.extension.tmx.TMXParser.startElement(TMXParser.java:161)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:143)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:513)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.extension.tmx.TMXLoader.load(TMXLoader.java:117)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.extension.tmx.TMXLoader.loadFromAsset(TMXLoader.java:102)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at com.meowcatfighter.goodygreen.scene.GameScene.loadLevel(GameScene.java:96)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at com.meowcatfighter.goodygreen.scene.GameScene.createScene(GameScene.java:85)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at com.meowcatfighter.goodygreen.scene.SceneManager.setGameScene(SceneManager.java:75)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at com.meowcatfighter.goodygreen.scene.MainMenuScene.onMenuItemClicked(MainMenuScene.java:66)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.entity.scene.menu.MenuScene.onAreaTouched(MenuScene.java:139)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.entity.scene.Scene.onAreaTouchEvent(Scene.java:413)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.entity.scene.Scene.onSceneTouchEvent(Scene.java:357)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.entity.scene.CameraScene.onSceneTouchEvent(CameraScene.java:64)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.entity.scene.Scene.onChildSceneTouchEvent(Scene.java:420)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.entity.scene.Scene.onSceneTouchEvent(Scene.java:338)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.engine.Engine.onTouchScene(Engine.java:452)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.engine.Engine.onTouchEvent(Engine.java:438)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.input.touch.controller.BaseTouchController$TouchEventRunnablePoolItem.run(BaseTouchController.java:102)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:54)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:1)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.util.adt.pool.PoolUpdateHandler.onUpdate(PoolUpdateHandler.java:88)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.input.touch.controller.BaseTouchController.onUpdate(BaseTouchController.java:62)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.engine.Engine.onUpdate(Engine.java:584)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
04-25 08:36:01.716: E/AndroidRuntime(13119):    at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)

(edit - Much thanks to Matej Spili for editing the LogCat! It's much easier on the eyes now! :D)

EDIT 4/29/14

So, so I spoke to bjorn, the maker of Tiled.

  • Me - it just seems to not matter what code i use though because it's always that error
  • Me - when i look one of the example tmx files, at the end it looks like....

    <objectgroup name="Unwalkable" width="400" height="21">
    
  • Me - but when i look out the tmx file i created, there is no height and width specification. how do you specify the height/width of an object layer?
  • bjorn - dpod: Those attributes are no longer written out.
  • bjorn - dpod: AndEngine should be fixed to not need them. They were basically always meaningless since object groups have no size restriction.
  • bjorn - These function names like "getTMXObjectGroupProperties" or "containsTMXProperty" are absolutely crazy...
  • bjorn - In Tiled, that code would be more like: "foreach (ObjectGroup *group, map->objectGroups()) { if (group->hasProperty("wall")) { ...
  • IRC - [15:02] == bjorn [~quassel@pdpc/supporter/active/bjorn]
  • IRC - [15:02] == realname : Thorbjørn Lindeijer
  • IRC - [15:02] == channels : #tiled
  • IRC - [15:02] == server : asimov.freenode.net [TX, USA]
  • IRC - [15:02] == account : bjorn
  • IRC - [15:02] == End of WHOIS
  • Me - oh my gosh you're the guy who made tiled?!

That was fun haha. But now I've got load of more questions! What on earth is foreach?

GoodyGreen
  • 13
  • 3

2 Answers2

0

Your .tmx file is just an xml with some information about your tiled created map.

It seems that SAX (the Simple API for XML parser) is trying to get a width attribute from it, but it's not being able to find it.

Following up andengine SAXUtils.java:

final String value = pAttributes.getValue("", pAttributeName);

pAttributes is of type Attributes:

http://www.saxproject.org/apidoc/org/xml/sax/Attributes.html#getValue(java.lang.String, java.lang.String)

Returns: The attribute value as a string, or null if the attribute is not in the list.

Check if your .tmx file has the width property, that the parser is expecting.

(GoodyGreen- Woops. I edited the wrong post. Removing edit and placing it in question.)

GoodyGreen
  • 13
  • 3
rvalerio
  • 489
  • 5
  • 5
  • Thanks for your support. I was able to remove the object layer all together and made the map show up on screen on GLES2. The example TMX file looked funny and had width and height attributes for the object layer, which I don't think you can configure in the Tiled application itself. I didn't manage to create wall objects in GLES2 though, but I've decided to do all this stuff in anchor center. I'm running into a host of different problems though, but if you're willing to assist me I appreciate it and will keep this updated. Thanks for your time :) – GoodyGreen Apr 29 '14 at 18:21
  • Ok so I got caught up in where I was in GLES 2. Now I'm getting the same error I was receiving in GLES 2. "No value found for attribute: 'width'" I'm looking for a andengine anchor center example that shows how to turn TMX objects into rectangles and items I can manipulate and use in andengine. I'll just scrap the example code I'm using where it trys to implement rectangles. If you're familiar with that sort of think your help is much appreciated (: – GoodyGreen Apr 29 '14 at 19:27
  • So I had the privilege to talk to bjorn who made Tiled. The conversation is too long for this, so I'll post it as an edit to my original post. – GoodyGreen Apr 29 '14 at 22:25
0

I've been getting support at the AndEngine forum. Special thanks to Therdiday for helping me every step of the way and to bjorn for making time to give me valuable pointers here and there.

The solution is that the TMX extension itself is made rather clunky. To satisfy the requirements of the extension, you must manually edit the TMX file itself in an editor (you can do this in eclipse if you want) and add a "height=x" and "width=x" value, where x equals literally any number, for every object layer in your TMX file.

I suppose not every TMX extension is like this, but the one I used by RealMayo needed it. Therdiday recommended his version as it does not require those empty attributes. Also, "BTW, the only difference between my version and the default anchor center version is its implementation of bounded Cameras and polyline support." https://github.com/Therdiday/AndEngineTMXTiledMapExtension

Anyway, if anyone has a similar problem, send me a message. I can provide more information.

GoodyGreen
  • 13
  • 3