为什么我的矩形不显示在JavaFX上?

时间:2017-11-08 04:14:16

标签: java javafx

尝试一个简单的游戏实现

    public class LocationHome extends Region {
Image homeBGimage;
int lheight, lwidth;


public void LocationHome(Location location) {
    this.setStyle("-fx-background-image: url(" + "'images/blackgrid.jpeg'" + ");" + "-fx-background-size: cover;");
    lheight = location.getLocationHeight(); //Location method call
    lwidth = location.getLocationWidth(); //Location method call
    this.setPrefSize(lheight, lwidth);
}

public void placePlayer(PlayerCharacter player) {
    //Create a PlayerSprite and position it as wanted
    Image img = new Image("images/blackgrid.jpeg");
    PlayerSprite playerSprite = new PlayerSprite(player, player.getID(), Color.AQUA);
    this.layoutInArea(playerSprite, player.getPosition().getUL().getX(), player.getPosition().getUL().getY(), playerSprite.getPlayerSize(), playerSprite.getPlayerSize(), 0, HPos.CENTER, VPos.BASELINE);
    this.getChildren().addAll(playerSprite);
}
}

我的playerSprites只是目前没有显示的矩形。 PlayerSprite构造函数是从名为LocationHome的对象中调用的,该对象扩展了Region。

     Group rootPane = new Group();
     World guiWorld = new WorldImpl(); //This is my game model
     BorderPane locationPane = new BorderPane(); //locationPane designated for rendering a Location
     guiCharacters = new HashMap<>();
     int id=0;
     for(PlayerCharacter each : guiWorld.getCharacters()) {
        guiCharacters.put(id, each);
        gridLocation.placePlayer(each);
        id++;
     }
    locationPane.getChildren().addAll(gridLocation);
    rootPane.getChildren().add(locationPane);
     currScene = new Scene( rootPane, 1024, 1024 ); //Passing the rootPane/group to currScene
    stage.setScene(currScene); //Make currScene contents visible
    stage.setTitle("Spoon Game");
    stage.show();

然后,对于我的主要JavaFX应用程序......

{{1}}

0 个答案:

没有答案