Hi guys
I’m still developing a platformer, but I don’t get to draw a polygon on my screen. Im using a Group-Node as the root, that is used as a parent for the Scene-Object. Then canvas is then added. I’m not using a Layout/Stack-Pane/Grid-Pane…
I’m having a player object that is containing an Object of class HUD(displaying stats and stuff). I can draw Images without problems, but how can i draw a Rectangle/Polygon onto a canvas?
@Override
public void start(Stage primaryStage) throws Exception
{
primaryStage.setTitle("Platformer");
Group root = new Group();
Scene scene = new Scene(root, WIDTH, HEIGHT);
Canvas canvas = new Canvas(WIDTH,HEIGHT);
root.getChildren().add(canvas);
GraphicsContext gc = canvas.getGraphicsContext2D();
MapManager.getInstance().loadAllMaps("maps");
tileMap = MapManager.getInstance().getCurrentTileMap();
player = new Player(tileMap);
player.setX(64);
player.setY(64);
scene.setOnKeyPressed(
event -> {
String code = event.getCode().toString();
if(code == "W")
{
player.setJumping(true);
}
if(code == "A")
{
player.setLeft(true);
}
if(code == "D")
{
player.setRight(true);
}
});
scene.setOnKeyReleased(
event -> {
String code = event.getCode().toString();
if(code == "A")
{
player.setLeft(false);
}
if(code == "D")
{
player.setRight(false);
}
});
AnimationTimer at = new AnimationTimer()
{
@Override
public void handle(long now)
{
update();
render(gc);
}
};
at.start();
primaryStage.setScene(scene);
primaryStage.show();
}
Any ideas how to?
Greetz HalfNoob