2017-07-13 4 views
0

でこれは私のコードです: メイン:。illegalStateExceptionを持つim: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である()のspawn( "敵")は、それが .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(); 
    } 

} 

誰もが何か問題が感謝を助けてください見るん!

+0

これは私が以前に聞いたことがない 'com.almasb.fxgl'ライブラリに非常に固有のようです - あなたが開発者からサポートできるかどうかを確認してください –

答えて

1

パッケージがないようです。メインクラスにパッケージがない場合、アノテーションプロセッサは無効になります。両方のクラスを同じパッケージに入れて、プロセッサがファクトリクラスを取得するようにしてください。

また、手動で工場をgetGameWorld().setEntityFactory(...)で設定することもできます。前者の方法は、使用中の他の注釈がある場合に好ましい。

+0

ありがとうAlmas! –

+0

私はそれらをすべて1つのパッケージに入れて、私に同じエラーを与えているのですが、私はlibを間違ってインポートした可能性がありますか? –

+0

私はそれを修正しました。私はFactoryクラスのインスタンスを手動で作成する必要がありました。 –

関連する問題