• libgdx 3D 瞄准星和隐藏鼠标


    1. 瞄准星

     1 /**画瞄准星*/
     2     private void drawSight(){
     3         debugRenderer.begin(ShapeRenderer.ShapeType.Line);
     4         float w = 50;
     5         float h = 40;
     6         Rectangle rect = new Rectangle((Gdx.graphics.getWidth()-w)/2, (Gdx.graphics.getHeight()-h)/2, w, h);
     7         debugRenderer.setColor(new Color(0, 1, 0, 1));
     8         debugRenderer.rect(rect.x, rect.y, rect.width, rect.height);
     9 
    10         //画十字线
    11         debugRenderer.line((Gdx.graphics.getWidth()-2*w)/2,Gdx.graphics.getHeight()/2,(Gdx.graphics.getWidth()+2*w)/2,Gdx.graphics.getHeight()/2);
    12         debugRenderer.line(Gdx.graphics.getWidth()/2,(Gdx.graphics.getHeight()-2*h)/2,Gdx.graphics.getWidth()/2,(Gdx.graphics.getHeight()+2*h)/2);
    13         debugRenderer.end();
    14     }
    debugRenderer = new ShapeRenderer();
    debugRenderer.setProjectionMatrix(stage.getCamera().combined);

    其中stage是ui用的,比如显示个FPS之类的,或者其他用户界面

    效果图:

    2. 隐藏鼠标指针

     1 /**隐藏鼠标指针*/
     2     private void hideCursor(){
     3         if (Gdx.app.getType() != Application.ApplicationType.Desktop)
     4             return;
     5         if (emptyCursor == null) {
     6             if (Mouse.isCreated()) {
     7                 int min = org.lwjgl.input.Cursor.getMinCursorSize();
     8                 IntBuffer tmp = BufferUtils.newIntBuffer(min * min);
     9                 try {
    10                     emptyCursor = new org.lwjgl.input.Cursor(min, min, min / 2, min / 2, 1, tmp, null);
    11                 } catch (LWJGLException e) {
    12                     e.printStackTrace();
    13                 }
    14             } else {
    15                 System.out.println("Could not create empty cursor before Mouse object is created");
    16             }
    17         }
    18         if (Mouse.isInsideWindow())
    19             try {
    20                 Mouse.setNativeCursor(false ? null : emptyCursor);
    21             } catch (LWJGLException e) {
    22                 e.printStackTrace();
    23             }
    24     }
    private org.lwjgl.input.Cursor emptyCursor;

    我抄来的,详情见:https://gist.github.com/mattdesl/4255483 

    //TODO 准星在调整窗口大小后有问题。

  • 相关阅读:
    P3368 【模板】树状数组 2
    P3374 【模板】树状数组 1
    P1631 序列合并
    P1387 最大正方形
    P1197 [JSOI2008]星球大战
    P2866 [USACO06NOV]糟糕的一天Bad Hair Day
    P1196 [NOI2002]银河英雄传说
    SP1805 HISTOGRA
    P1334 瑞瑞的木板
    2019信息学夏令营游记
  • 原文地址:https://www.cnblogs.com/hanhongmin/p/3868673.html
Copyright © 2020-2023  润新知