@Override public void update(BaseGame game, GameTime time) { if (this.changed) { if (this.newCursorImage != null) { Cursor currentCursor = this.cursorCacheMap.get(this.newCursorImage); if (currentCursor == null) { currentCursor = Gdx.graphics.newCursor(this.newCursorImage, 0, 0); this.cursorCacheMap.put(this.newCursorImage, currentCursor); } Gdx.graphics.setCursor(currentCursor); } else if (this.cursor != null) { Gdx.graphics.setSystemCursor(this.cursor); } } else { Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow); } this.newCursorImage = null; this.cursor = null; this.changed = false; }
private static Cursor.SystemCursor systemCursor(KrCursor cursor) { switch (cursor) { case ARROW: return Cursor.SystemCursor.Arrow; case IBEAM: return Cursor.SystemCursor.Ibeam; case CROSSHAIR: return Cursor.SystemCursor.Crosshair; case HAND: return Cursor.SystemCursor.Hand; case HORIZONTAL_RESIZE: return Cursor.SystemCursor.HorizontalResize; case VERTICAL_RESIZE: return Cursor.SystemCursor.VerticalResize; default: return Cursor.SystemCursor.Arrow; } }
public static void dispose() { if (stage != null) { stage.dispose(); } if (stackFont != null) { stackFont.dispose(); } if (batch != null) { batch.dispose(); } if (defaultCursor != null) { defaultCursor.dispose(); defaultCursor = null; } if (toolCursors != null) { for (Cursor cursor : toolCursors.values()) { cursor.dispose(); } toolCursors.clear(); } }
/** * Sets the cursor image. * * @param image * The image. */ public void setCursorImage(Pixmap image) { if (image == null) { throw new IllegalArgumentException("Cursor image cannot be null."); } if (!cursorCacheMap.containsKey(image)) { Cursor newCursor = Gdx.graphics.newCursor(image, 0, 0); this.cursorCacheMap.put(image, newCursor); Gdx.graphics.setCursor(newCursor); } else { Gdx.graphics.setCursor(cursorCacheMap.get(image)); } }
@Override public void setSystemCursor(Cursor.SystemCursor cursor) { this.newCursorImage = null; if (this.cursor != cursor) { this.cursor = cursor; changed = true; } }
@Override public void resetCursor() { this.newCursorImage = null; this.cursor = null; changed = false; Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow); }
private static Cursor getCursorForPath(AssetManager am, String texturePath) { Pixmap pixmap = null; if (texturePath != null) { Texture cursorTexture = am.get(texturePath); TextureData data = cursorTexture.getTextureData(); if (!data.isPrepared()) { data.prepare(); } pixmap = data.consumePixmap(); } return Gdx.graphics.newCursor(pixmap, 0, 0); }
@Override public void setCursor (Cursor cursor) { if (cursor == null) { glfwSetCursor(window, 0); } else { cursor.setSystemCursor(); } }
private void setCustomCursor () { Cursor.SystemCursor targetCursor; if (vertical) { targetCursor = Cursor.SystemCursor.VerticalResize; } else { targetCursor = Cursor.SystemCursor.HorizontalResize; } if (currentCursor != targetCursor) { Gdx.graphics.setSystemCursor(targetCursor); currentCursor = targetCursor; } }
public static void loadGameStageAssets() { // colors greenColor = new Color(0.1f , 0.8f , 0.1f,1f); // music laserMillenium = Gdx.audio.newMusic(Gdx.files.internal("music/Laser_Millenium.ogg")); laserMillenium.setVolume(Game.VOLUME_MUSIC); laserMillenium.setLooping(true); laserMillenium.play(); // sounds laserTurretFire = Gdx.audio.newSound(Gdx.files.internal("towers/lasertower/fx/bubaproducer__laser-shot-silenced.wav")); //laserTurretFire.play(0.5f); // laser texture laserSmall = new Texture(Gdx.files.internal("projectiles/lasers/laser-small.png")); plastmaProj = new Texture(Gdx.files.internal("projectiles/lasers/plastma-projectile.png")); missile = new Texture(Gdx.files.internal("projectiles/missile/missile.png")); // bloodworm bloodWormSkeleton = loadSkeleton("enemies/bloodworm/skeleton.atlas","enemies/bloodworm/skeleton.json"); bloodWormAnimationState = new AnimationState(new AnimationStateData(bloodWormSkeleton.getData())); // bird birdSkeleton = loadSkeleton("enemies/bird/skeleton.atlas","enemies/bird/skeleton.json"); birdAnimationState = new AnimationState(new AnimationStateData(birdSkeleton.getData())); // healtbar enemyGreenHealthbarBG = new Sprite(loadTexture("enemies/healthbar-green.png")); enemyRedHealthbarBG = new Sprite(loadTexture("enemies/healthbar-red.png")); // Tower laserTowerSkeleton = loadSkeleton("towers/lasertower/skeleton.atlas","towers/lasertower/skeleton.json"); laserTowerAnimationState = new AnimationState(new AnimationStateData(laserTowerSkeleton.getData())); plastmaTowerSkeleton = loadSkeleton("towers/plastma-tower/skeleton.atlas", "towers/plastma-tower/skeleton.json"); plastmaTowerAnimationState = new AnimationState(new AnimationStateData(plastmaTowerSkeleton.getData())); missleTowerSkeleton = loadSkeleton("towers/missle-tower/skeleton.atlas", "towers/missle-tower/skeleton.json"); missleTowerAnimationState = new AnimationState(new AnimationStateData(missleTowerSkeleton.getData())); // Coin coinSkeleton = loadSkeleton("misc/coin/skeleton.atlas", "misc/coin/skeleton.json"); coinSkeleton.getRootBone().setScale(0.16f); coinAnimationState = new AnimationState(new AnimationStateData(coinSkeleton.getData())); // fonts // skin Cursor slickArrow = Gdx.graphics.newCursor(new Pixmap(Gdx.files.getFileHandle("slick_arrow-arrow.png", Files.FileType.Internal)), 0, 0); Gdx.graphics.setCursor(slickArrow); }
@Override public Optional<Cursor> getRequestedCursor() { return Optional.empty(); }
@Override public Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot) { return null; }
@Override public Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot) { // TODO Auto-generated method stub return null; }
@Override public void setCursor(Cursor cursor) { // TODO Auto-generated method stub }
@Override public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) { if (pointer == -1) { Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow); } }
@Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Hand); }
public static void setCursorForTool(Tool tool) { Cursor cursor = tool != null ? toolCursors.get(tool) : null; Gdx.graphics.setCursor(cursor != null ? cursor : defaultCursor); }
@Override public Cursor newCursor (Pixmap pixmap, int xHotspot, int yHotspot) { return new JglfwCursor(this, pixmap, xHotspot, yHotspot); }
private void changeCursor() { // last 2 params are the cursor hotspot Cursor customCursor = Gdx.graphics.newCursor( new Pixmap(Gdx.files.internal("images/crosshair1.png")), 32, 32); Gdx.graphics.setCursor(customCursor); }
/** * Sets cursor that will be used as default when {@link #restoreDefaultCursor()} is called, for example by VisUI widget. * @param defaultCursor default cursor, can't be null */ public static void setDefaultCursor (Cursor defaultCursor) { if (defaultCursor == null) throw new IllegalArgumentException("defaultCursor can't be null"); CursorManager.defaultCursor = defaultCursor; CursorManager.systemCursorAsDefault = false; }
/** * Sets cursor that will be used as default when {@link #restoreDefaultCursor()} is called, for example by Vis widget. * @param defaultCursor default cursor from {@link Cursor.SystemCursor}, can't be null */ public static void setDefaultCursor (Cursor.SystemCursor defaultCursor) { if (defaultCursor == null) throw new IllegalArgumentException("defaultCursor can't be null"); CursorManager.defaultSystemCursor = defaultCursor; CursorManager.systemCursorAsDefault = true; }
@Override public Cursor newCursor (Pixmap pixmap, int xHotspot, int yHotspot) { return null; }
@Override public void setCursor (Cursor cursor) { }
/** * Resets the cursor image to the default one. * * @see SystemCursor#Arrow */ public void resetCursorImage() { Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow); }
/** * The cursor returned by this method should always be the same instance * It should be disposed in the dispose method implementation * * @return an optional cursor object if a cursor is requested */ Optional<Cursor> getRequestedCursor();
@Override public void setCursor(Cursor cursor) { }
public void setSystemCursor(Cursor.SystemCursor cursor);