• 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 准星在调整窗口大小后有问题。

  • 相关阅读:
    创建窗体不抢夺焦点的方法
    控件绘制的四种方法
    ATL CAxWindow类创建问题一则
    PE文件版本那些事儿
    GDIPlus非典型误用一例
    stl 常用代码
    For each loop in Native C++
    win7 64 下 VS2008 调试、退出时错误的解决
    DailyWallpaper v1.03 released
    编程当道,学点Python技术好傍身
  • 原文地址:https://www.cnblogs.com/hanhongmin/p/3868673.html
Copyright © 2020-2023  润新知