Custom cursor implementation #7

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent 683d056992
commit a0c0adfc6e
  1. BIN
      sprites/cursor.png
  2. 12
      src/sig/JavaProjectTemplate.java
  3. 24
      src/sig/engine/Panel.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

@ -32,8 +32,10 @@ public class JavaProjectTemplate {
Player pl = new Player();
Sprite bookSpr = new Sprite("book.png");
JavaProjectTemplate(){
public void initializeGame(){
//Initialize your game here.
game.Cursor_SetCursor(new Sprite("cursor.png"),0,0);
}
public void updateGame(double fElapsedTime) {
@ -66,6 +68,14 @@ public class JavaProjectTemplate {
if (Mouse.mouseWheel==MouseScrollValue.DOWN) {
System.out.println("Scroll down!");
}
if (Mouse.isPressed(3)) {
if (game.Cursor_IsVisible()) {
game.Cursor_Hide();
} else {
game.Cursor_Show();
}
}
}
public void drawGame() {

@ -25,6 +25,8 @@ import java.awt.event.KeyListener;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Cursor;
import sig.JavaProjectTemplate;
public class Panel extends JPanel implements Runnable,KeyListener {
@ -61,6 +63,8 @@ public class Panel extends JPanel implements Runnable,KeyListener {
public static Panel p;
public static JFrame f;
static Cursor currentCursor = new Cursor(Cursor.DEFAULT_CURSOR);
public static void InitializeEngine(JavaProjectTemplate instance){
System.setProperty("sun.java2d.transaccel", "True");
System.setProperty("sun.java2d.d3d", "True");
@ -89,6 +93,8 @@ public class Panel extends JPanel implements Runnable,KeyListener {
p.render();
gameInstance.initializeGame();
long lastGameTime = System.nanoTime();
long dt = 0;
while (true) {
@ -238,6 +244,24 @@ public class Panel extends JPanel implements Runnable,KeyListener {
* pixel is your canvas!
*/
public boolean Cursor_IsVisible(){
return !f.getCursor().getName().equals("INVISIBLE");
}
public void Cursor_Hide(){
f.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().getImage(""), new java.awt.Point(0,0), "INVISIBLE"));
}
public void Cursor_Show(){
f.setCursor(currentCursor);
}
public void Cursor_SetCursor(Sprite cursorimg,int x_origin,int y_origin){
currentCursor=Toolkit.getDefaultToolkit().createCustomCursor(cursorimg.img, new java.awt.Point(x_origin,y_origin), "CUSTOM");
f.setCursor(currentCursor);
}
public void Cursor_ResetCursor(){
f.setCursor(Cursor.getDefaultCursor());
}
public /* abstract */ void render(){
gameInstance.drawGame();

Loading…
Cancel
Save