当前位置: 首页>>代码示例>>Java>>正文


Java QueryCallback类代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.QueryCallback的典型用法代码示例。如果您正苦于以下问题:Java QueryCallback类的具体用法?Java QueryCallback怎么用?Java QueryCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueryCallback类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了QueryCallback类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: raycastPoint

import com.badlogic.gdx.physics.box2d.QueryCallback; //导入依赖的package包/类
public static List<RaycastHit> raycastPoint(final Vector2 pointToTest) {
	final List<RaycastHit> hits = new ArrayList<RaycastHit>();
	Vector2 end = pointToTest.add(new Vector2(1, 1));
	//TODO move to static single object
	physic.physicWorld.QueryAABB(new QueryCallback() {
		@Override
		public boolean reportFixture(Fixture fixture) {
			if (fixture.testPoint(pointToTest)) {
				hits.add(new RaycastHit(fixture, pointToTest));
			}
			return true;
		}
	}, pointToTest.x < end.x ? pointToTest.x : end.x, pointToTest.y < end.y ? pointToTest.y : end.y,
			pointToTest.x > end.x ? pointToTest.x : end.x, pointToTest.y > end.y ? pointToTest.y : end.y);

	return hits;
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:18,代码来源:JPhysic.java

示例2: setSoloMode

import com.badlogic.gdx.physics.box2d.QueryCallback; //导入依赖的package包/类
/** Changes to second stage of the game. */
public void setSoloMode() {
    soloMode = true;
    for (final Minion minion : minions) {
        minion.setDestroyed(true);
    }
    // Spawning additional obstacles:
    final boolean[] isTaken = new boolean[1];
    final QueryCallback callback = new QueryCallback() {
        @Override
        public boolean reportFixture(final Fixture fixture) {
            isTaken[0] = true;
            return false;
        }
    };
    final float width = Box2DUtil.WIDTH * 2f / 5f - Block.HALF_SIZE;
    final float height = Box2DUtil.HEIGHT * 2f / 5f - Block.HALF_SIZE;
    for (int index = 0; index < 15; index++) {
        final float x = MathUtils.random(-width, width);
        final float y = MathUtils.random(-height, height);
        isTaken[0] = false;
        world.QueryAABB(callback, x - Block.HALF_SIZE, y - Block.HALF_SIZE, x + Block.HALF_SIZE,
                y + Block.HALF_SIZE);
        if (!isTaken[0]) {
            gameController.addBlock(spawnBlock(x, y));
        }
    }
}
 
开发者ID:BialJam,项目名称:M-M,代码行数:29,代码来源:Box2DService.java

示例3: touchDown

import com.badlogic.gdx.physics.box2d.QueryCallback; //导入依赖的package包/类
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
	/*
	 * Define a new QueryCallback. This callback will be used in
	 * world.QueryAABB method.
	 */
	QueryCallback queryCallback = new QueryCallback() {

		@Override
		public boolean reportFixture(Fixture fixture) {
			boolean testResult;

			/*
			 * If the hit point is inside the fixture of the body, create a
			 * new MouseJoint.
			 */
			if (testResult = fixture.testPoint(touchPosition.x,
					touchPosition.y)) {
				mouseJointDef.bodyB = fixture.getBody();
				mouseJointDef.target.set(touchPosition.x, touchPosition.y);
				mouseJoint = (MouseJoint) world.createJoint(mouseJointDef);
			}

			return testResult;
		}
	};

	/* Translate camera point to world point */
	camera.unproject(touchPosition.set(screenX, screenY, 0));

	/*
	 * Query the world for all fixtures that potentially overlap the touched
	 * point.
	 */
	world.QueryAABB(queryCallback, touchPosition.x, touchPosition.y,
			touchPosition.x, touchPosition.y);

	return true;
}
 
开发者ID:Leakedbits,项目名称:Codelabs,代码行数:40,代码来源:DragAndDropSample.java

示例4: QueryAABB

import com.badlogic.gdx.physics.box2d.QueryCallback; //导入依赖的package包/类
public void QueryAABB(final QueryCallback pCallback, final float pLowerX, final float pLowerY, final float pUpperX, final float pUpperY) {
	this.mWorld.QueryAABB(pCallback, pLowerX, pLowerY, pUpperX, pUpperY);
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:4,代码来源:PhysicsWorld.java

示例5: touchDown

import com.badlogic.gdx.physics.box2d.QueryCallback; //导入依赖的package包/类
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
	if (!gameRunning) {
		return false;
	}
	float x = ((float)screenX) / Gdx.graphics.getWidth() * Constants.WIDTH;
	float y = Constants.HEIGHT - ((float)screenY) / Gdx.graphics.getHeight() * Constants.HEIGHT;
	world.QueryAABB(new QueryCallback() {
		@Override
		public boolean reportFixture(Fixture fixture) {
			if (fixture.getBody().getUserData() instanceof Entity && ((Entity)fixture.getBody().getUserData()).isDestroyable()) {
				if (gameRunning) {
					world.destroyBody(fixture.getBody());
					if (boxesLeft > 0) {
						--boxesLeft;
					}
					if (boxesLeft == 0) {
						victoryChecker = new VictoryChecker() {
							@Override
							public void check() {
								boolean sleeping = true;
								Iterator<Body> i = world.getBodies();
								while (i.hasNext()) {
									Body body = i.next();
									if (body.getUserData() instanceof Entity) {
										if (body.isAwake()) {
											sleeping = false;
										}
									}
								}
								if (sleeping) {
									victory();
								}
							}
						};
					}
				}
			}
			return false;
		}
	}, x, y, x, y);
	return false;
}
 
开发者ID:matachi,项目名称:geometri-destroyer,代码行数:44,代码来源:GeometriDestroyer.java

示例6: LolScene

import com.badlogic.gdx.physics.box2d.QueryCallback; //导入依赖的package包/类
/**
 * Construct a new scene
 *
 * @param media  All image and sound assets for the game
 * @param config The game-wide configuration
 */
LolScene(Media media, Config config) {
    mMedia = media;
    mConfig = config;
    // compute the width and height, in meters
    float w = config.mWidth / config.mPixelMeterRatio;
    float h = config.mHeight / config.mPixelMeterRatio;
    // set up the game camera, with (0, 0) in the bottom left
    mCamera = new OrthographicCamera(w, h);
    mCamera.position.set(w / 2, h / 2, 0);
    mCamera.zoom = 1;

    // set up the event lists
    mOneTimeEvents = new ArrayList<>();
    mRepeatEvents = new ArrayList<>();

    // set default camera bounds
    mCamBound = new Vector2();
    mCamBound.set(w, h);

    // create a world with no default gravitational forces
    mWorld = new World(new Vector2(0, 0), true);

    // set up the containers for holding anything we can render
    mRenderables = new ArrayList<>(5);
    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
    mTouchVec = new Vector3();
    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)) {
                BaseActor hs = (BaseActor) fixture.getBody().getUserData();
                if (hs.mEnabled) {
                    mHitActor = hs;
                    return false;
                }
            }
            return true;
        }
    };

    // prepare other collections
    mGlyphLayout = new GlyphLayout();
    mTapHandlers = new ArrayList<>();
}
 
开发者ID:mfs409,项目名称:liblol,代码行数:57,代码来源:LolScene.java


注:本文中的com.badlogic.gdx.physics.box2d.QueryCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。