Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/AlmasB/FXGL into dev
Browse files Browse the repository at this point in the history
pull
  • Loading branch information
AlmasB committed Mar 24, 2024
2 parents f68cd7c + 728d582 commit f89f28d
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
60 changes: 60 additions & 0 deletions fxgl-samples/src/main/java/sandbox/SoftwareCursorSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* FXGL - JavaFX Game Library. The MIT License (MIT).
* Copyright (c) AlmasB ([email protected]).
* See LICENSE for details.
*/

package sandbox;

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.ui.SoftwareCursor;
import javafx.scene.paint.Color;

import static com.almasb.fxgl.dsl.FXGL.*;

/**
* @author Alex Moore ([email protected])
* @author Leo Waters ([email protected])
* @author Poppy Eyres ([email protected])
*/
public class SoftwareCursorSample extends GameApplication {
SoftwareCursor Cursor;

@Override
protected void initSettings(GameSettings settings) {
// settings.addEngineService(QuestService.class);
}


@Override
protected void initInput() {
//hide default cursor
getGameScene().getRoot().setCursor(javafx.scene.Cursor.NONE);
}
@Override
protected void initGame() {
//create software cursor
Cursor = new SoftwareCursor(Color.PINK);
getGameScene().getRoot().getChildren().add(Cursor.getCursorNode());

//initialize cursor position
Cursor.setPositionX((double) getGameScene().getAppWidth() / 2);
Cursor.setPositionY((double) getGameScene().getAppHeight() / 2);
}



@Override
protected void onUpdate(double tpf) {
//Cursor.setPosition(getInput().getMouseXWorld(), getInput().getMouseYWorld());
//Cursor.setPositionX(getInput().getMouseXWorld());
//Cursor.setPositionY(getInput().getMouseYWorld());
Cursor.translatePosition(tpf,tpf);
}


public static void main(String[] args) {
launch(args);
}
}
63 changes: 63 additions & 0 deletions fxgl-scene/src/main/java/com/almasb/fxgl/ui/SoftwareCursor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* FXGL - JavaFX Game Library. The MIT License (MIT).
* Copyright (c) AlmasB ([email protected]).
* See LICENSE for details.
*/

package com.almasb.fxgl.ui;

import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;

/**
* @author Alex Moore ([email protected])
* @author Leo Waters ([email protected])
* @author Poppy Eyres ([email protected])
*/
public class SoftwareCursor {
Polygon Cursor;
static Double[] defaultPoints = {0.0, 0.0,0.0, 20.0, 20.0, 5.0};

// creates software cursor with colour
public SoftwareCursor(Color color){
this(defaultPoints, color);
}
// creates software cursor with colour and points to draw
public SoftwareCursor(Double[] Points, Color color){
Cursor = new Polygon();
Cursor.getPoints().addAll(Points);
Cursor.setFill(color);

}
//gets the node to be added to the scene
public Node getCursorNode(){
return Cursor;
}
//sets X position
public void setPositionX(double x){
Cursor.setTranslateX(x);
}
//sets Y position
public void setPositionY(double y){
Cursor.setTranslateY(y);
}
//sets X and Y position
public void setPosition(double x, double y){
Cursor.setTranslateX(x);
Cursor.setTranslateY(y);
}
//moves X position by x
public void translatePositionX(double x){
Cursor.setTranslateX(Cursor.translateXProperty().doubleValue()+x);
}
//moves Y position by y
public void translatePositionY(double y){
Cursor.setTranslateY(Cursor.translateYProperty().doubleValue()+y);
}
//moves X & Y positions by x & y
public void translatePosition(double x,double y){
Cursor.setTranslateX(Cursor.translateXProperty().doubleValue()+x);
Cursor.setTranslateY(Cursor.translateYProperty().doubleValue()+y);
}
}

0 comments on commit f89f28d

Please sign in to comment.