List of usage examples for com.badlogic.gdx.physics.box2d Fixture testPoint
public boolean testPoint(float x, float y)
From source file:edu.lehigh.cse.lol.Level.java
License:Open Source License
/** * Construct a level. This is mostly using defaults, so the main work is in * camera setup/*from w w w . j av a 2 s. co m*/ * * @param width The width of the level, in meters * @param height The height of the level, in meters */ Level(int width, int height) { // clear any timers Timer.instance().clear(); // Set up listeners for touch events. Gestures are processed before // non-gesture touches, and non-gesture touches are only processed when // a gesture is not detected. InputMultiplexer mux = new InputMultiplexer(); mux.addProcessor(new GestureDetector(new LolGestureManager())); mux.addProcessor(new LolInputManager()); Gdx.input.setInputProcessor(mux); // reset the per-level object store mLevelFacts = new TreeMap<>(); mLevelActors = new TreeMap<>(); // save the camera bounds mCamBoundX = width; mCamBoundY = height; // warn on strange dimensions if (width < Lol.sGame.mWidth / Physics.PIXEL_METER_RATIO) Util.message("Warning", "Your game width is less than 1/10 of the screen width"); if (height < Lol.sGame.mHeight / Physics.PIXEL_METER_RATIO) Util.message("Warning", "Your game height is less than 1/10 of the screen height"); // set up the game camera, with 0,0 in the bottom left mGameCam = new OrthographicCamera(Lol.sGame.mWidth / Physics.PIXEL_METER_RATIO, Lol.sGame.mHeight / Physics.PIXEL_METER_RATIO); mGameCam.position.set(Lol.sGame.mWidth / Physics.PIXEL_METER_RATIO / 2, Lol.sGame.mHeight / Physics.PIXEL_METER_RATIO / 2, 0); mGameCam.zoom = 1; // set up the heads-up display camera int camWidth = Lol.sGame.mWidth; int camHeight = Lol.sGame.mHeight; mHudCam = new OrthographicCamera(camWidth, camHeight); mHudCam.position.set(camWidth / 2, camHeight / 2, 0); // the background camera is like the hudcam mBgCam = new ParallaxCamera(camWidth, camHeight); mBgCam.position.set(camWidth / 2, camHeight / 2, 0); mBgCam.zoom = 1; // set up the renderables for (int i = 0; i < 5; ++i) mRenderables.add(new ArrayList<Renderable>()); // set up the callback for finding out who in the physics world was // touched mTouchCallback = new QueryCallback() { @Override public boolean reportFixture(Fixture fixture) { // if the hit point is inside the fixture of the body we report // it if (fixture.testPoint(mTouchVec.x, mTouchVec.y)) { Actor hs = (Actor) fixture.getBody().getUserData(); if (hs.mVisible) { mHitActor = hs; return false; } } return true; } }; }
From source file:skyranger.game.ClickCallback.java
License:Apache License
@Override public boolean reportFixture(Fixture fixture) { if (fixture.testPoint(getLastClick().x, getLastClick().y)) { for (IBox2dObject obj : ObjectsManager.getObjects().values()) { if (fixture.getBody() == obj.getBody()) { obj.setFixture(fixture); GameMouseEvent.mouseClickOnObject(obj); playScreen.setSelectedObjId(obj.getId()); this.hitId = obj.getId(); this.clickedObject = obj; this.clickedObject .setAngle(this.clickedObject.getBody().getAngle() * MathUtils.radiansToDegrees); }/* w w w . jav a 2 s . co m*/ } setHitBody(fixture.getBody()); return false; } else return true; }