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

 

转载于:https://www.cnblogs.com/hanhongmin/p/3868673.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值