本文整理汇总了Java中com.badlogic.ashley.core.Engine.addEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Engine.addEntity方法的具体用法?Java Engine.addEntity怎么用?Java Engine.addEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.ashley.core.Engine
的用法示例。
在下文中一共展示了Engine.addEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
public static void add(Engine engine) {
// build cave
Maker maker = new Maker().setMesh("assets/models/cave_old.obj")
.setShader("assets/shaders/cc/depth.vert.glsl", "assets/shaders/cc/depth.frag.glsl")
.setTexture(0, "assets/textures/RockPerforated0029_1_seamless_S.png")
.setTexture(4, "assets/textures/fog-gradient-03.png")
.setTextureScale(12f);
engine.addEntity(maker.build());
// build seafloor
maker.setMesh("assets/models/seafloor.obj")
.setShader("assets/shaders/cc/caustic.vert.glsl", "assets/shaders/cc/caustic.frag.glsl");
engine.addEntity(maker.build());
addMainCamera(engine);
addAuxiliaryQuantumLightConvolutionAcceleratorBuffer();
addFishflock(engine, 7, 7, 7, 0.4f);
addSkybox(engine);
//addFishflock(engine, 3, 5, 3, 0.5f);
}
示例2: intervalSystem
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Test
public void intervalSystem () {
Engine engine = new Engine();
IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy();
ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(IntervalComponentSpy.class).get());
ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class);
engine.addSystem(intervalSystemSpy);
for (int i = 0; i < 10; ++i) {
Entity entity = new Entity();
entity.add(new IntervalComponentSpy());
engine.addEntity(entity);
}
for (int i = 1; i <= 10; ++i) {
engine.update(deltaTime);
for (int j = 0; j < entities.size(); ++j) {
assertEquals(i / 2, im.get(entities.get(j)).numUpdates);
}
}
}
示例3: create
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Override
public void create()
{
GameSettingsComponent settings = new GameSettingsComponent();
settings.setGuiWidth(width);
settings.setGuiHeight(height);
settings.setWorldToScreen(32f);
settings.setGravity(new Vector2(0, -9.81f));
settings.setTimeStep(1 / 300f);
settings.setPaused(false);
GameWorld gameWorld = new GameWorld(settings);
engine = new Engine();
engine.addEntity(gameWorld);
engine.addSystem(new AccumulatorSystem());
engine.addSystem(new MovementSystem());
engine.addSystem(new JumpingSystem());
setScreen(new GameScreen(engine, gameWorld.getId()));
}
示例4: intervalSystem
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Test
public void intervalSystem() {
Engine engine = new Engine();
IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy();
ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.getFor(IntervalComponentSpy.class));
ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class);
engine.addSystem(intervalSystemSpy);
for (int i = 0; i < 10; ++i) {
Entity entity = new Entity();
entity.add(new IntervalComponentSpy());
engine.addEntity(entity);
}
for (int i = 1; i <= 10; ++i) {
engine.update(deltaTime);
for (int j = 0; j < entities.size(); ++j) {
assertEquals(i / 2, im.get(entities.get(j)).numUpdates);
}
}
}
示例5: create
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Override
public void create() {
Gdx.input.setInputProcessor(inputProcessor);
physicsWorld = new World(new Vector2(0, -30), true);
entityEngine = new Engine();
entityEngine.addEntity(new CharacterEntity(physicsWorld));
entityEngine.addSystem(new PhysicsSystem(physicsWorld));
entityEngine.addSystem(new InputSystem(inputProcessor));
SceneRenderer sceneRenderer = new SceneRenderer(physicsWorld);
renderer = new PixelatedRenderer(sceneRenderer);
Level level = Level.fromMapPath("levels/level0.tmx");
level.populatePhysicsWorld(physicsWorld);
}
示例6: addMainCamera
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
private static void addMainCamera(Engine engine) {
Pose pose = new Pose();
pose.position.set(0, 0, 1f);
pose.orientation.rotateY((float) Math.PI);
//pose.setFocus(new Vector3f());
Entity cam = new Entity();
cam.add(new Camera());
cam.add(new PathFollower(0.017f));
cam.add(pose);
engine.addEntity(cam);
}
示例7: addSkybox
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
private static void addSkybox(Engine engine){
Maker maker = new Maker().setMesh(new SkyboxMaker().make(new SegmentedMeshBuilder(Primitive.TRIANGLES),115))
.setShader("assets/shaders/cc/skybox.vert.glsl", "assets/shaders/cc/skybox.frag.glsl")
.setTexture(4, "assets/textures/fog-gradient-03.png");
engine.addEntity(maker.build());
}
示例8: shouldIterateEntitiesWithCorrectFamily
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shouldIterateEntitiesWithCorrectFamily () {
final Engine engine = new Engine();
final Family family = Family.all(ComponentA.class, ComponentB.class).get();
final IteratingSystemMock system = new IteratingSystemMock(family);
final Entity e = new Entity();
engine.addSystem(system);
engine.addEntity(e);
// When entity has ComponentA
e.add(new ComponentA());
engine.update(deltaTime);
assertEquals(0, system.numUpdates);
// When entity has ComponentA and ComponentB
system.numUpdates = 0;
e.add(new ComponentB());
engine.update(deltaTime);
assertEquals(1, system.numUpdates);
// When entity has ComponentA, ComponentB and ComponentC
system.numUpdates = 0;
e.add(new ComponentC());
engine.update(deltaTime);
assertEquals(1, system.numUpdates);
// When entity has ComponentB and ComponentC
system.numUpdates = 0;
e.remove(ComponentA.class);
e.add(new ComponentC());
engine.update(deltaTime);
assertEquals(0, system.numUpdates);
}
示例9: shouldIterateEntitiesWithCorrectFamily
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shouldIterateEntitiesWithCorrectFamily () {
final Engine engine = new Engine();
final Family family = Family.all(OrderComponent.class, ComponentB.class).get();
final SortedIteratingSystemMock system = new SortedIteratingSystemMock(family);
final Entity e = new Entity();
engine.addSystem(system);
engine.addEntity(e);
// When entity has OrderComponent
e.add(new OrderComponent("A", 0));
engine.update(deltaTime);
// When entity has OrderComponent and ComponentB
e.add(new ComponentB());
system.expectedNames.addLast("A");
engine.update(deltaTime);
// When entity has OrderComponent, ComponentB and ComponentC
e.add(new ComponentC());
system.expectedNames.addLast("A");
engine.update(deltaTime);
// When entity has ComponentB and ComponentC
e.remove(OrderComponent.class);
e.add(new ComponentC());
engine.update(deltaTime);
}
示例10: entityOrder
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Test
public void entityOrder () {
Engine engine = new Engine();
final Family family = Family.all(OrderComponent.class).get();
final SortedIteratingSystemMock system = new SortedIteratingSystemMock(family);
engine.addSystem(system);
Entity a = createOrderEntity("A", 0);
Entity b = createOrderEntity("B", 1);
Entity c = createOrderEntity("C", 3);
Entity d = createOrderEntity("D", 2);
engine.addEntity(a);
engine.addEntity(b);
engine.addEntity(c);
system.expectedNames.addLast("A");
system.expectedNames.addLast("B");
system.expectedNames.addLast("C");
engine.update(0);
engine.addEntity(d);
system.expectedNames.addLast("A");
system.expectedNames.addLast("B");
system.expectedNames.addLast("D");
system.expectedNames.addLast("C");
engine.update(0);
orderMapper.get(a).zLayer = 3;
orderMapper.get(b).zLayer = 2;
orderMapper.get(c).zLayer = 1;
orderMapper.get(d).zLayer = 0;
system.forceSort();
system.expectedNames.addLast("D");
system.expectedNames.addLast("C");
system.expectedNames.addLast("B");
system.expectedNames.addLast("A");
engine.update(0);
}
示例11: GameScreen
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
public GameScreen(Engine engine, long gameWorldId)
{
this.engine = engine;
gameWorld = engine.getEntity(gameWorldId);
GameSettingsComponent settings = Mappers.gameSettingsMap.get(gameWorld);
ui = new Ui(settings.getWorldWidth(), settings.getWorldHeight());
engine.addEntity(ui);
}
示例12: shouldIterateEntitiesWithCorrectFamily
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shouldIterateEntitiesWithCorrectFamily() {
final Engine engine = new Engine();
final Family family = Family.getFor(ComponentA.class, ComponentB.class);
final IteratingSystemMock system = new IteratingSystemMock(family);
final Entity e = new Entity();
engine.addSystem(system);
engine.addEntity(e);
//When entity has ComponentA
e.add(new ComponentA());
engine.update(deltaTime);
assertEquals(0, system.numUpdates);
//When entity has ComponentA and ComponentB
system.numUpdates = 0;
e.add(new ComponentB());
engine.update(deltaTime);
assertEquals(1, system.numUpdates);
//When entity has ComponentA, ComponentB and ComponentC
system.numUpdates = 0;
e.add(new ComponentC());
engine.update(deltaTime);
assertEquals(1, system.numUpdates);
//When entity has ComponentB and ComponentC
system.numUpdates = 0;
e.remove(ComponentA.class);
e.add(new ComponentC());
engine.update(deltaTime);
assertEquals(0, system.numUpdates);
}
示例13: spawnPowerup
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
private static void spawnPowerup(Engine engine, Entity entity) {
if (MathUtils.random() > 1 - ServiceLocator.getEntityComponent().getGameSettings().getPowerupSpawnChance()) {
Entity powerup = createPowerup(entity);
if (powerup != null) engine.addEntity(powerup);
}
}
示例14: addFishflock
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
private static void addFishflock(Engine engine, int nrX, int nrY, int nrZ, float margin){
Boid protoypeBoid = new Boid();
protoypeBoid.influence = 0.3f;
Maker maker = new Maker().setMesh("assets/models/zierfisch.obj")
.setShader("assets/shaders/cc/fish.vert.glsl", "assets/shaders/cc/fish.frag.glsl")
.setTexture(0, "assets/textures/fish-diffuse.png")
.setTexture(1, "assets/textures/fish-emission.png")
.setTexture(4, "assets/textures/fog-gradient-03.png")
.setScale(0.5f)
.add(protoypeBoid);
Vector3f center = new Vector3f(0,0,-5);
for(int x = 0; x < nrX; x++){
for(int y = 0; y < nrY; y++){
for(int z = 0; z < nrZ; z++){
Entity fish = maker.setPosition(
x*margin - (nrX-1)*margin/2 + center.x,
y*margin - (nrY-1)*margin/2 + center.y,
z*margin - (nrZ-1)*margin/2 + center.z
).build();
engine.addEntity(fish);
}
}
}
ImmutableArray<Entity> allEnts = engine.getEntities();
Entity randomEnt1 = allEnts.get(allEnts.size() - 1);
Light light1 = new Light();
light1.color.set(.3f, 0.9f, 1f);
light1.intensity = 0.7f;
randomEnt1.add(light1);
/*Entity startLight = new Entity();
startLight.add(new Light());
startLight.add(new Pose());
startLight.getComponent(Light.class).color.set(1.0f, 0.7f, 0.94f);
startLight.getComponent(Light.class).intensity = 0.01f;
startLight.getComponent(Pose.class).position.y = 1.0f;
engine.addEntity(startLight);*/
/*
Entity randomEnt2 = allEnts.get((int) (Math.random() * allEnts.size()));
Light light2 = new Light();
light2.color.set(.6f, 1f, 1f);
light2.intensity = 1.0f;
randomEnt2.add(light2);
Entity randomEnt3 = allEnts.get((int) (Math.random() * allEnts.size()));
Light light3 = new Light();
light3.color.set(.7f, 1f, 1f);
light3.intensity = 10.0f;
randomEnt3.add(light3);*/
}
示例15: prepareEngine
import com.badlogic.ashley.core.Engine; //导入方法依赖的package包/类
private static Engine prepareEngine (int numEntities) {
Engine engine = new Engine();
engine.addSystem(new MovementSystem());
engine.addSystem(new StateSystem());
engine.addSystem(new CollisionSystem());
engine.addSystem(new RemovalSystem());
for (int i = 0; i < numEntities; ++i) {
Entity entity = new Entity();
if (Constants.shouldHaveComponent(ComponentType.POSITION, i)) {
PositionComponent pos = new PositionComponent();
pos.pos.x = MathUtils.random(Constants.MIN_POS, Constants.MAX_POS);
pos.pos.y = MathUtils.random(Constants.MIN_POS, Constants.MAX_POS);
entity.add(pos);
}
if (Constants.shouldHaveComponent(ComponentType.MOVEMENT, i)) {
MovementComponent mov = new MovementComponent();
mov.velocity.x = MathUtils.random(Constants.MIN_VEL, Constants.MAX_VEL);
mov.velocity.y = MathUtils.random(Constants.MIN_VEL, Constants.MAX_VEL);
mov.accel.x = MathUtils.random(Constants.MIN_ACC, Constants.MAX_ACC);
mov.accel.y = MathUtils.random(Constants.MIN_ACC, Constants.MAX_ACC);
entity.add(mov);
}
if (Constants.shouldHaveComponent(ComponentType.RADIUS, i)) {
RadiusComponent rad = new RadiusComponent();
rad.radius = MathUtils.random(Constants.MIN_RADIUS, Constants.MAX_RADIUS);
entity.add(rad);
}
if (Constants.shouldHaveComponent(ComponentType.STATE, i)) {
entity.add(new StateComponent());
}
engine.addEntity(entity);
}
return engine;
}