List of usage examples for com.badlogic.gdx Input justTouched
public boolean justTouched();
From source file:com.davidykay.shootout.screens.GameLoop.java
License:Apache License
@Override public void update(Application app) { simulation.update(app.getGraphics().getDeltaTime()); Input input = app.getInput(); final boolean ACCELEROMETER_STEERING = false; if (ACCELEROMETER_STEERING) { if (input.getAccelerometerY() < 0) simulation.moveShipLeft(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10); else// ww w .jav a2 s .c o m simulation.moveShipRight(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10); } if (input.isKeyPressed(Keys.DPAD_LEFT)) simulation.moveShipLeft(app.getGraphics().getDeltaTime(), 0.5f); if (input.isKeyPressed(Keys.DPAD_RIGHT)) simulation.moveShipRight(app.getGraphics().getDeltaTime(), 0.5f); if (input.justTouched()) { final float x = input.getX(); final float y = input.getY(); Vector3 nearVector = new Vector3(x, y, 0); Vector3 farVector = new Vector3(x, y, 1); renderer.unproject(nearVector); renderer.unproject(farVector); /** Vector tracing between the near plane and the far plane **/ Vector3 inVector = new Vector3(nearVector); final Plane gamePlane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)); Ray pickRay = renderer.getCamera().getPickRay(x, y); Vector3 intersection = new Vector3(); Vector3 finalVector; if (FLAT_MODE) { // Flat Mode if (Intersector.intersectRayPlane(pickRay, gamePlane, intersection)) { finalVector = new Vector3(intersection); if (finalVector.equals(nearVector)) { Gdx.app.log(TAG, String.format("Near Vector! finalVector:(%s)", finalVector.toString())); } else { Gdx.app.log(TAG, String.format("INTERSECTION! finalVector:(%s)", finalVector.toString())); } } else { Gdx.app.log(TAG, String.format("NO INTERSECTION. nearVector:(%s)", nearVector.toString())); finalVector = new Vector3(nearVector); } } else { // 3D Mode finalVector = new Vector3(nearVector); //for (Alien alien : aliens) { // if ( // Intersector.intersectRayPlane( // pickRay, // gamePlane, // intersection // ) // ) { // } //} } //simulation.tapShot(nearVector); //simulation.tapShot(finalVector); simulation.tapRay(pickRay); } else { // If we haven't been touched, let's look at the orientation. This in an attempt to lower // impulse from user's finger. float azimuth = input.getAzimuth(); float pitch = input.getPitch(); float roll = input.getRoll(); simulation.updateOrientation(azimuth, pitch, roll); } }
From source file:com.digitale.screens.GameLoop.java
License:Open Source License
/** * @param input//from ww w . j ava 2s . c om * set touch co-ords so they match screen co-ords */ private void rectifyTouchCoords(Input input) { screenScaleX = Gdx.app.getGraphics().getWidth() / 800f; screenScaleY = Gdx.app.getGraphics().getHeight() / 480f; camera.unproject(GameLoop.touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0)); int x = input.getX(); int y = input.getY(); if (input.justTouched()) { touch_x = input.getX(); touch_y = input.getY(); } if (input.isTouched()) { x += input.getX() - touch_x; y += touch_y - input.getY(); touch_x = input.getX(); // x; touch_y = input.getY(); // y; } touch_x = touch_x / screenScaleX; touch_y = touch_y / screenScaleY; if (Stardust3d.DEEPDEBUG) System.out.println("Width:" + Gdx.app.getGraphics().getWidth() + "Height:" + Gdx.app.getGraphics().getHeight() + "xscale:" + screenScaleX + " yscale:" + screenScaleY); }