Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Software Cursor, closes #1090 #1342

Merged
merged 4 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading