标签:des style blog http color io width 2014
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 准星在调整窗口大小后有问题。
libgdx 3D 瞄准星和隐藏鼠标,布布扣,bubuko.com
标签:des style blog http color io width 2014
原文地址:http://www.cnblogs.com/hanhongmin/p/3868673.html