-
-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/AlmasB/FXGL into dev
pull
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
fxgl-samples/src/main/java/sandbox/SoftwareCursorSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
63
fxgl-scene/src/main/java/com/almasb/fxgl/ui/SoftwareCursor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |