com.artemis.Entity.getComponent()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中com.artemis.Entity.getComponent()方法的一些代码示例,展示了Entity.getComponent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.getComponent()方法的具体详情如下:
包路径:com.artemis.Entity
类名称:Entity
方法名:getComponent

Entity.getComponent介绍

[英]Retrieves component from this entity.

Minimize usage of this. Use ComponentMapper instead.
[中]从该实体检索组件。
最大限度地减少使用此功能。改用ComponentMapper。

代码示例

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-jam

public static float distance( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pa.xy.x, pa.xy.y).dst(pb.xy.x, pb.xy.y);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-components-libgdx

public static float distance( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pa.x, pa.y).dst(pb.x, pb.y);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-jam

public static float distance2( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pa.xy.x, pa.xy.y).dst2(pb.xy.x, pb.xy.y);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-components-libgdx

public static float distance2( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pa.x, pa.y).dst2(pb.x, pb.y);
}

代码示例来源:origin: DaanVanYperen/artemis-odb-contrib

public static float distance2( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pa.xy.x, pa.xy.y).dst2(pb.xy.x, pb.xy.y);
}

代码示例来源:origin: DaanVanYperen/artemis-odb-contrib

public static float distance( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pa.xy.x, pa.xy.y).dst(pb.xy.x, pb.xy.y);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-components-libgdx

public static float angle( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pb.x, pb.y).sub(pa.x, pa.y).angle();
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-jam

public static float angle( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pb.xy.x, pb.xy.y).sub(pa.xy.x, pa.xy.y).angle();
}

代码示例来源:origin: DaanVanYperen/artemis-odb-contrib

public static float angle( final Entity a, final Entity b)
{
  final Pos pa = (Pos)a.getComponent(Pos.class);
  final Pos pb = (Pos)b.getComponent(Pos.class);
  return tmp.set(pb.xy.x, pb.xy.y).sub(pa.xy.x, pa.xy.y).angle();
}

代码示例来源:origin: junkdog/artemis-odb

/**
 * Slower retrieval of components from this entity.
 * <p>
 * Minimize usage of this. Use {@link ComponentMapper} instead.
 * </p>
 * @param <T>
 *         the expected return component class type
 * @param type
 *         the expected return component class type
 * @return component that matches, or {@code null} if none is found
 */
@SuppressWarnings("unchecked")
public <T extends Component> T getComponent(Class<T> type) {
  ComponentTypeFactory tf = world.getComponentManager().typeFactory;
  return (T) getComponent(tf.getTypeFor(type));
}

代码示例来源:origin: net.onedaybeard.artemis/artemis-odb

/**
 * Slower retrieval of components from this entity.
 * <p>
 * Minimize usage of this. Use {@link ComponentMapper} instead.
 * </p>
 * @param <T>
 *         the expected return component class type
 * @param type
 *         the expected return component class type
 * @return component that matches, or {@code null} if none is found
 */
@SuppressWarnings("unchecked")
public <T extends Component> T getComponent(Class<T> type) {
  ComponentTypeFactory tf = world.getComponentManager().typeFactory;
  return (T) getComponent(tf.getTypeFor(type));
}

代码示例来源:origin: yichen0831/Bomberman_libGdx

@Override
  public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
    if (fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) {
      Entity bombEntity = (Entity) fixture.getBody().getUserData();
      kickingBomb = bombEntity.getComponent(Bomb.class);
      return 0;
    }
    return 0;
  }
};

代码示例来源:origin: junkdog/artemis-odb

private void readComponentsArchetype(Json json, Entity e, JsonValue component) {
  SaveFileFormat.ComponentIdentifiers identifiers = serializationState.componentIdentifiers;
  archetypeMapper.transmute(e, archetype);
  while (component != null) {
    assert (component.name() != null);
    Class<? extends Component> componentType = identifiers.getType(component.name);
    readComponent(json, component, e.getComponent(componentType));
    component = component.next;
  }
}

代码示例来源:origin: junkdog/artemis-odb

private void readComponentsArchetype(Json json, Entity e, JsonValue component) {
  SaveFileFormat.ComponentIdentifiers identifiers = serializationState.componentIdentifiers;
  archetypeMapper.transmute(e, archetype);
  while (component != null) {
    assert (component.name() != null);
    Class<? extends Component> componentType = identifiers.getType(component.name);
    readComponent(json, component, e.getComponent(componentType));
    component = component.next;
  }
}

代码示例来源:origin: net.onedaybeard.artemis/artemis-odb-serializer-json

private void readComponentsArchetype(Json json, Entity e, JsonValue component) {
  SaveFileFormat.ComponentIdentifiers identifiers = serializationState.componentIdentifiers;
  archetypeMapper.transmute(e, archetype);
  while (component != null) {
    assert (component.name() != null);
    Class<? extends Component> componentType = identifiers.getType(component.name);
    readComponent(json, component, e.getComponent(componentType));
    component = component.next;
  }
}

代码示例来源:origin: junkdog/artemis-odb

private boolean findReferences(int entityId, Field f, BitVector referencedIds) {
  Component c = world.getEntity(entityId).getComponent(f.getDeclaringClass());
  if (c == null)
    return false;
  Class type = f.getType();
  try {
    if (type.equals(int.class)) {
      return updateReferenced((Integer)f.get(c), referencedIds);
    } else if (type.equals(Entity.class)) {
      return updateReferenced((Entity)f.get(c), referencedIds);
    } else if (type.equals(IntBag.class)) {
      return updateReferenced((IntBag)f.get(c), referencedIds);
    } else if (type.equals(Bag.class)) {
      return updateReferenced((Bag)f.get(c), referencedIds);
    } else {
      throw new RuntimeException("unknown type: " + type);
    }
  } catch (ReflectionException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: net.onedaybeard.artemis/artemis-odb-serializer

private boolean findReferences(int entityId, Field f, BitVector referencedIds) {
  Component c = world.getEntity(entityId).getComponent(f.getDeclaringClass());
  if (c == null)
    return false;
  Class type = f.getType();
  try {
    if (type.equals(int.class)) {
      return updateReferenced((Integer)f.get(c), referencedIds);
    } else if (type.equals(Entity.class)) {
      return updateReferenced((Entity)f.get(c), referencedIds);
    } else if (type.equals(IntBag.class)) {
      return updateReferenced((IntBag)f.get(c), referencedIds);
    } else if (type.equals(Bag.class)) {
      return updateReferenced((Bag)f.get(c), referencedIds);
    } else {
      throw new RuntimeException("unknown type: " + type);
    }
  } catch (ReflectionException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: yichen0831/Bomberman_libGdx

@Override
  public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
    if (fixture.getFilterData().categoryBits == GameManager.INDESTRUCTIIBLE_BIT) {
      canExplodeThrough = false;
      return 0;
    }
    if (fixture.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) {
      canExplodeThrough = false;
      Entity e = (Entity) fixture.getBody().getUserData();
      Breakable breakable = e.getComponent(Breakable.class);
      breakable.state = Breakable.State.EXPLODING;
      return 0;
    }
    return 0;
  }
};

代码示例来源:origin: yichen0831/Bomberman_libGdx

Player player = e.getComponent(Player.class);
  player.receivedDamage++;
} else if (fixtureB.getFilterData().categoryBits == GameManager.PLAYER_BIT) {
  Entity e = (Entity) fixtureB.getBody().getUserData();
  Player player = e.getComponent(Player.class);
  player.receivedDamage++;
  Enemy enemy = e.getComponent(Enemy.class);
  enemy.receivedDamage++;
} else if (fixtureB.getFilterData().categoryBits == GameManager.ENEMY_BIT) {
  Entity e = (Entity) fixtureB.getBody().getUserData();
  Enemy enemy = e.getComponent(Enemy.class);
  enemy.receivedDamage++;
  Bomb bomb = e.getComponent(Bomb.class);
  bomb.countDown = 0;
} else if (fixtureB.getFilterData().categoryBits == GameManager.BOMB_BIT) {
  Entity e = (Entity) fixtureB.getBody().getUserData();
  Bomb bomb = e.getComponent(Bomb.class);
  bomb.countDown = 0;
  Breakable breakable = e.getComponent(Breakable.class);
  breakable.state = Breakable.State.EXPLODING;
} else if (fixtureB.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) {
  Entity e = (Entity) fixtureB.getBody().getUserData();
  Breakable breakable = e.getComponent(Breakable.class);
  breakable.state = Breakable.State.EXPLODING;
if (fixtureA.getFilterData().categoryBits == GameManager.PLAYER_BIT) {

代码示例来源:origin: yichen0831/Bomberman_libGdx

while (!remoteBombQueue.isEmpty() && remoteBombQueue.peek().getComponent(Bomb.class) == null) {
  remoteBombQueue.remove();
  Bomb remoteBomb = remoteBombEntity.getComponent(Bomb.class);
  remoteBomb.countDown = 0;

相关文章