Render用のTask
であるRenderTask
を
public class RenderTask extends Task<Integer> {
final private MainApp app;
private boolean exit;
public RenderTask(MainApp app){
this.app = app;
}
@Override
public Integer call() {
System.out.println("RenderTask start");
EntityNode theEntity = EntityNode.create(app.entityRegistry.get(0), 64, 64);
addEntity(theEntity);
for(;;){//here
if(exit)
break ;
theEntity.setPosition(theEntity.getX()+0.1, theEntity.getY());
System.out.println(theEntity);
try {
System.out.println(GameSystem.getNormalThreadSleepTime());
Thread.sleep(GameSystem.getNormalThreadSleepTime()/* return 1000/60*/);
} catch (InterruptedException interrupted) {
System.err.println("ERR");
}
}
System.out.println("RenderTask end");
return 0;
}
public EntityNode addEntity(EntityNode entityNode){
app.groupEntity.getChildren().add(entityNode);
return entityNode;
}
public EntityNode addEntity(Entity entity, double posX, double posY){
return this.addEntity(EntityNode.create(entity, posX, posY));
}
public void exit(){
this.exit = true;
}
}
と宣言し,MainAppを
public class MainApp extends Application {
final public AnchorPane pane = new AnchorPane();
final public GameTask gameTask = new GameTask(this);
final public GameServerTask gameServerTask = new GameServerTask(this);
final public RenderTask renderTask = new RenderTask(this);
final public EntityRegistry entityRegistry = new EntityRegistry();
final public Group groupEntity = new Group();
public static void main(String[] args){
MainApp.launch(args);
}
@Override
public void start(Stage stage) {
stage.setTitle("INVASION");
stage.setWidth(GameSystem.windowWidth);
stage.setHeight(GameSystem.windowHeight);
stage.setMaxWidth(GameSystem.windowWidth);
stage.setMaxHeight(GameSystem.windowHeight);
stage.setMinWidth(GameSystem.windowWidth);
stage.setMinHeight(GameSystem.windowHeight);
stage.setScene(new Scene(pane));
new Thread(gameTask).start();
new Thread(gameServerTask).start();
Platform.runLater(renderTask);
gameServerTask.order(new Order("init", 0));
pane.getChildren().add(groupEntity);
stage.show();
}
}
RenderTask
の//here
部分のループが一度の実行で終わってしまっています。
しかしfor
の外は実行されていないのでどこかで処理が止まっているのかと思います。
凡ミスかもしれませんが回答お願いします。