javafxtmxfxgl

No EntityFactory has a method annotated @Spawns()


I have trouble with testing the TMX feature. I wanted to load a simple TMX file into my sample FXGL App (JavaFX Game Library). Any ideas?

Error:

10:52:31.888 [FXGL Background Thread 4 ] WARN TMXLevelLoader - TiledMap generated from 1.7.2. Supported version: 1.2.3. Some features may not be parsed fully. 10:52:32.001 [FXGL Background Thread 4 ] WARN TMXLevelLoader - Parse error java.lang.IllegalArgumentException: No EntityFactory has a method annotated @Spawns() at com.almasb.fxgl.entity/com.almasb.fxgl.entity.GameWorld.create(GameWorld.kt:413) at com.almasb.fxgl.entity/com.almasb.fxgl.entity.level.tiled.TMXLevelLoader.createObjectLayerEntities(TMXLevelLoader.kt:132) at com.almasb.fxgl.entity/com.almasb.fxgl.entity.level.tiled.TMXLevelLoader.load(TMXLevelLoader.kt:50) at com.almasb.fxgl.all/com.almasb.fxgl.app.services.FXGLAssetLoaderService.loadLevel(FXGLAssetLoaderService.kt:446) at com.almasb.fxgl.all/com.almasb.fxgl.dsl.FXGL$Companion.setLevelFromMap(FXGL.kt:521) at com.almasb.fxgl.all/com.almasb.fxgl.dsl.FXGL.setLevelFromMap(FXGL.kt)

TMX:

 <objectgroup id="2" name="Object Layer 1">
  <object id="2" name="tree" x="513.036" y="352.019" width="63.2967" height="64.4072"/>
 </objectgroup>

App:

@Override
protected void initGameVars(Map<String, Object> context) {
    FXGL.getGameWorld().addEntityFactory(new SimpleEntityFactory());
}

@Override
protected void initGame() {
    FXGL.setLevelFromMap("level01.tmx");
}

Factory:

public class SimpleEntityFactory implements EntityFactory {

      @Spawns("tree")
      public Entity newTree(SpawnData data) {
         return FXGL.entityBuilder(data).view(new Circle(8, Color.BLUE)).build();
      }

}

Solution

  • I would guess that in the .tmx file, the created object has no type, hence its type is "" -- empty String. Your factory SimpleEntityFactory does not have a method annotated @Spawns(""), hence the error.