這是我的代碼: 主營::EntityFactory沒有設置!與fxgl
import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.core.math.FXGLMath;
import com.almasb.fxgl.settings.GameSettings;
import javafx.util.Duration;
public class Main extends GameApplication
{
public static void main(String[] args)
{
launch(args);
}
@Override
protected void initSettings(GameSettings gameSettings)
{
gameSettings.setTitle("Shooter");
gameSettings.setVersion("1.0");
gameSettings.setHeight(1000);
gameSettings.setWidth(1600);
gameSettings.setCloseConfirmation(false);
gameSettings.setProfilingEnabled(false);
gameSettings.setIntroEnabled(false);
gameSettings.setMenuEnabled(false);
}
@Override
protected void initGame()
{
getMasterTimer().runAtInterval(() -> {
getGameWorld().spawn("Enemy",
FXGLMath.random(0, (int) getWidth() - 40),
FXGLMath.random(0, (int) getHeight()/2 - 40)
);
}, Duration.seconds(1));
}
}
問題是getgamewolrd()產卵( 「敵人」),它說 .IllegalStateException:EntityFactory沒有設置! 這是我的工廠類:
import com.almasb.fxgl.annotation.SetEntityFactory;
import com.almasb.fxgl.annotation.Spawns;
import com.almasb.fxgl.ecs.Entity;
import com.almasb.fxgl.entity.Entities;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.component.CollidableComponent;
import com.almasb.fxgl.entity.control.ProjectileControl;
import javafx.geometry.Point2D;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
@SetEntityFactory
public class Factory implements EntityFactory
{
@Spawns("Bullet")
public Entity newBullet(SpawnData data) {
return Entities.builder()
.from(data)
.type(EntityTypes.BULLET)
.viewFromNodeWithBBox(new Rectangle(10, 2, Color.BLUE))
.with(new CollidableComponent(true))
.with(new ProjectileControl(new Point2D(0, -1), 300))
.build();
}
@Spawns("Enemy")
public Entity newEnemy(SpawnData data) {
return Entities.builder()
.from(data)
.type(EntityTypes.ENEMY)
.viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED))
.with(new CollidableComponent(true))
.build();
}
}
沒有人看到什麼錯了,請幫助謝謝!
這似乎是非常具體的'com.almasb.fxgl'庫,我從來沒有聽說過 - 試圖看看你是否可以從開發者支持 –