本文整理汇总了Java中com.badlogic.gdx.physics.box2d.Fixture.isSensor方法的典型用法代码示例。如果您正苦于以下问题:Java Fixture.isSensor方法的具体用法?Java Fixture.isSensor怎么用?Java Fixture.isSensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.physics.box2d.Fixture
的用法示例。
在下文中一共展示了Fixture.isSensor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleFootContact
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
private void handleFootContact(Contact contact, boolean onBeginContact) {
Fixture footSensor = getFootSensor();
if (contact.getFixtureA() == footSensor || contact.getFixtureB() == footSensor) {
Fixture otherFixture =
(footSensor == contact.getFixtureA()) ? contact.getFixtureB() : contact.getFixtureA();
if (!otherFixture.isSensor()) {
if (onBeginContact) {
if (numFootContacts == 0) {
land();
}
numFootContacts++;
} else {
numFootContacts--;
}
numFootContacts = Math.max(0, numFootContacts);
}
}
}
示例2: processCollision
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
@Override
public void processCollision(Fixture colliderA, Fixture colliderB, boolean collisionSignal) {
if (colliderA.isSensor() && !colliderB.isSensor()) {
Integer indexEntityA = (Integer) colliderA.getBody().getUserData();
Integer indexEntityB = (Integer) colliderB.getBody().getUserData();
String tagSensorA = (String) colliderA.getUserData();
if (indexEntityA != null && indexEntityB != null && tagSensorA != null && tagSensorA.equals("RadarSensor")) {
GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB);
if (entityB != null) {
for (SensorEntity entity : sensorGroup.getEntities()) {
RadarSensor radar = entity.getRadarSensor();
if (entityB.getTags().values.contains(radar.targetTag)) {
if (collisionSignal) {
Indexed.addEntityInSensor(entity, entityB);
} else {
Indexed.removeEntityInSensor(entity, entityB);
}
radar.collisionSignal = collisionSignal;
}
}
}
}
}
}
示例3: beginContact
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
@Override
public void beginContact(Contact contact) {
// TODO Auto-generated method stub
Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB();
//logger.info("contact");
if (state == GAME_RUNNING) {
if (fixtureA.getFilterData().categoryBits == CATEGORY_PLAYER &&
fixtureB.getFilterData().categoryBits == CATEGORY_ENEMY) {
//fixtureA.getFilterData().maskBits = 0;
state = GAME_OVER_SETUP;
}
else if (fixtureA.getFilterData().categoryBits == CATEGORY_ENEMY &&
fixtureB.getFilterData().categoryBits == CATEGORY_PLAYER) {
//fixtureB.getFilterData().maskBits = 0;
state = GAME_OVER_SETUP;
}
}
if ((fixtureA.isSensor() == true && fixtureB.getFilterData().categoryBits == CATEGORY_PLAYER)
|| (fixtureB.isSensor() == true && fixtureA.getFilterData().categoryBits == CATEGORY_PLAYER)) {
state = BALL_DESTROYED;
}
}
示例4: fixtureToColor
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
/**
* Translates b2d Fixture to appropriate color, depending on body state/type
* Modify to suit your needs
* @param fixture
* @return
*/
private static Color fixtureToColor(Fixture fixture) {
if (fixture.isSensor()) {
return Color.PINK;
} else {
Body body = fixture.getBody();
if (!body.isActive()) {
return Color.BLACK;
} else {
if (!body.isAwake()) {
return Color.RED;
} else {
switch (body.getType()) {
case StaticBody:
return Color.CYAN;
case KinematicBody:
return Color.WHITE;
case DynamicBody:
default:
return Color.GREEN;
}
}
}
}
}
示例5: processEntity
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
PhysicsComponent physics = App.engine.mappers.physics.get(entity);
BulletComponent bullet = App.engine.mappers.bullet.get(entity);
ChildComponent child = App.engine.mappers.child.get(entity);
//Iterate over all touching fixtures, checking to see if they have
// health, and deal damage as necessary
Array<Fixture> fixturesTouching = App.engine.systems.physics.getFixturesTouching(physics);
for (Fixture f : fixturesTouching){
//Should have no effect on sensors
if (f.isSensor()) continue;
PhysicsComponent p = (PhysicsComponent) f.getBody().getUserData();
if (p == null) continue;
Entity dealer = (child == null) ? entity : child.parentEntity;
dealDamage(dealer,p.ownerEntity,bullet.damage,physics.getRotation());
}
//disable bullet after colliding with anything
if (physics.getCollisionNormal() > 0) {
physics.setFilter(CollisionBits.Effects,CollisionBits.Mask_Effects);
entity.remove(BulletComponent.class);
//logger.debug("Entity #" + entity.getId() + ": damage disabled");
}
}
示例6: reportRayFixture
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
public float reportRayFixture(Fixture f,Vector2 p,Vector2 n,float fra){
if (f.isSensor() && ignoreSensors) return -1;
fixture = f;
body = f.getBody();
physics = (PhysicsComponent)body.getUserData();
point = p;
normal = n;
fraction = fra;
return fra;
}
示例7: fromFixture
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
public void fromFixture(Fixture f){
shapeModel = new ShapeModel(f.getShape());
Filter filterData = f.getFilterData();
filter.categoryBits = filterData.categoryBits;
filter.maskBits = filterData.maskBits;
filter.groupIndex = filterData.groupIndex;
sensor = f.isSensor();
density = f.getDensity();
friction = f.getFriction();
restitution = f.getRestitution();
}
示例8: processCollision
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
@Override
public void processCollision(Fixture colliderA, Fixture colliderB, boolean collisionSignal) {
if (colliderA.isSensor() && !colliderB.isSensor()) {
Integer indexEntityA = (Integer) colliderA.getBody().getUserData();
Integer indexEntityB = (Integer) colliderB.getBody().getUserData();
String tagSensorA = (String) colliderA.getUserData();
Body bodyB = colliderB.getBody();
for (Fixture fixture : bodyB.getFixtureList()) {
if(fixture.isSensor()) return;
}
if (indexEntityA != null && indexEntityB != null && tagSensorA != null) {
GameEntity entityA = Indexed.getInteractiveEntity(indexEntityA);
GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB);
if (entityA != null && entityB != null && tagSensorA != null) {
for (SensorEntity entity : sensorGroup.getEntities()) {
if (entity.getLink().ownerEntity == indexEntityA) {
NearSensor sensor = entity.getNearSensor();
if (sensor.targetTag != null && entityB.getTags().values.contains(sensor.targetTag)) {
if (collisionSignal) {
if (tagSensorA.equals("NearSensor")) {
sensor.distanceContactList.add(indexEntityB);
if (entity.getLink().sensorReference.contains("RadialGravity")) {
bodyB.setGravityScale(0);
bodyB.resetMassData();
}
} else if (tagSensorA.equals("ResetNearSensor")) {
sensor.resetDistanceContactList.add(indexEntityB);
}
} else {
if (tagSensorA.equals("NearSensor")) {
sensor.distanceContactList.remove(indexEntityB);
if (entity.getLink().sensorReference.contains("RadialGravity")) {
bodyB.setGravityScale(1);
bodyB.resetMassData();
}
} else if (tagSensorA.equals("ResetNearSensor")) {
sensor.resetDistanceContactList.remove(indexEntityB);
}
}
}
}
}
}
}
}
}
示例9: itemWithNonSensor
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
private static void itemWithNonSensor(final Fixture fixture, final Object userData) {
if ((userData instanceof Item) && !fixture.isSensor()) {
// ((Item) userData).reset();
// System.out.println(userData + " with non-sensor " + fixture.getBody().getUserData());
}
}
示例10: processEntity
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
PhysicsComponent physics = App.engine.mappers.physics.get(entity);
HealthComponent health = App.engine.mappers.health.get(entity);
StickyComponent sticky = App.engine.mappers.sticky.get(entity);
float collisionForce = physics.getCollisionNormal();
//Sticky projectiles
if (sticky != null && sticky.enabled){
Fixture stickyFixture = physics.getFixture(sticky.fixtureName);
if (stickyFixture != null){
boolean colliding = getContactCount(stickyFixture) > 0;
Array<Fixture> touchingFixtures = getFixturesTouching(stickyFixture);
for (Fixture f : touchingFixtures){
if (f.isSensor()) colliding = false;
else {
WeldJointDef jd = new WeldJointDef();
Body b1 = f.getBody(),
b2 = stickyFixture.getBody();
jd.initialize(b1,b2,b2.getWorldCenter());
world.createJoint(jd);
sticky.enabled = false;
break;
}
}
if (!colliding) physics.setRotation(physics.getLinearVelocity().angle());
}
}
//Collision Damage
if (health != null && collisionForce >= health.collisionDamageThreshold){
float dmg = collisionForce - health.collisionDamageThreshold;
App.engine.systems.damage.dealDamage(entity,dmg);
logger.debug(String.format("Collision damage: Entity#%d ; Force=%f ; Dmg=%f",
entity.getId(),collisionForce,dmg));
}
physics.clearCollisionNormal();
/*
//Anything outside of the world bounds is destroyed
if (!App.engine.entityBounds.contains(physics.getPosition()) &&
entity != App.engine.getLevel().getEntity()){
logger.debug("Destroy Entity #" + entity.getId() + ": outside of world bounds.");
App.engine.removeEntity(physics.ownerEntity);
}
*/
}