没有 EntityFactory 有注释为 @Spawns() 的方法
No EntityFactory has a method annotated @Spawns()
我在测试 TMX 功能时遇到了问题。我想将一个简单的 TMX 文件加载到我的示例 FXGL 应用程序(JavaFX 游戏库)中。有什么想法吗?
错误:
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>
应用程序:
@Override
protected void initGameVars(Map<String, Object> context) {
FXGL.getGameWorld().addEntityFactory(new SimpleEntityFactory());
}
@Override
protected void initGame() {
FXGL.setLevelFromMap("level01.tmx");
}
工厂:
public class SimpleEntityFactory implements EntityFactory {
@Spawns("tree")
public Entity newTree(SpawnData data) {
return FXGL.entityBuilder(data).view(new Circle(8, Color.BLUE)).build();
}
}
我猜想在 .tmx 文件中,创建的对象没有类型,因此它的类型是 ""
-- 空字符串。您的工厂 SimpleEntityFactory
没有注释的方法 @Spawns("")
,因此出现错误。
我在测试 TMX 功能时遇到了问题。我想将一个简单的 TMX 文件加载到我的示例 FXGL 应用程序(JavaFX 游戏库)中。有什么想法吗?
错误:
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>
应用程序:
@Override
protected void initGameVars(Map<String, Object> context) {
FXGL.getGameWorld().addEntityFactory(new SimpleEntityFactory());
}
@Override
protected void initGame() {
FXGL.setLevelFromMap("level01.tmx");
}
工厂:
public class SimpleEntityFactory implements EntityFactory {
@Spawns("tree")
public Entity newTree(SpawnData data) {
return FXGL.entityBuilder(data).view(new Circle(8, Color.BLUE)).build();
}
}
我猜想在 .tmx 文件中,创建的对象没有类型,因此它的类型是 ""
-- 空字符串。您的工厂 SimpleEntityFactory
没有注释的方法 @Spawns("")
,因此出现错误。