问题描述
我再次回来问具体问题,
我创建了一个世界,配置生成器,依此类推, 基于Artemis odb的ECS,可用于Libgdx, 一旦一切准备就绪并呈现,什么也不会呈现,
某些代码可能有助于寻找线索;
WorldConfiguration setup = new WorldConfigurationBuilder()
.with(new HelloSystemArtemis()) //basic
.with(new IGMessageSystem()) //HelloSystemArtemis clone
.with(new GroupManager()) //Needed
.with(new TagManager()) //Needed
//ACTIVES
.with(new EntitySpawnerSystem()) //Spawn Entities
//PASSIVES
.with(new CameraSystem()) //For sake
.with(new CollisionSystem()) //For sake
//.with(new ParticleSystem()) TO IMPLEMENT
//.with(new PlayerControlSystem()) TO IMPLEMENT
//ACTIVES,INPUT,LOGIC
.with(new PlayerAndWeaponRenderSystem()) // Render Player and Weapon
.with(new PlayerSystem()) //For handling Player displacements and actions
//.with(new WeaponSystem()) // TO IMPLEMENT
//ACTIVES,INteraCTION
//.with(new CombatSystem()) // TO IMPLEMENT
//.with(new CraftSystem()) // TO IMPLEMENT
//.with(new UpdateEquipmentSystem()) // TO IMPLEMENT
//.with(new EquipmentJewelryInsertSystem()) // TO IMPLEMENT
//ACTIVES,PHYSICS
.with(new PhysicsSystem()) //For sake
.with(new GravitySystem()) //For sake
//ACTIVES,CAMERA
.with(new CameraFocusSystem()) //For sake
.with(new CameraShakeSystem()) //For sake
//ACTIVES RENDERING
.with(new MapRenderSystem()) //Render Map
.with(new NameRenderSystem()) //Retrieving Player Name
.with(new PlayerLevelRenderSystem()) //Retrieving Player Level
.with(new HealthRenderSystem()) //Retrieving Player Health
.with(new ManaRenderSystem()) //Retrieving Player Mana
.with(new EnergyRenderSystem()) //Retrieving Player Energy
.with(new XPRenderSystem()) //Retrieving Player XP
//ACTIVES,MOVEMENTS AND STATUS
.with(new MovementSystem(this)) //done
.with(new StatusSystem(this)) //to verify
.with(new EnemySystem(this)) //to verify
.build();
world = new World(setup);
在渲染部分:
world.setDelta(delta);
world.process();
例如,我创建类似的MapEntities
public class MapFactoryArtemis {
public static OxyddiA game;
private static Assets assets = new Assets();
public static Entity createAthmosphere() {
Entity athmosphere = GameWorld.world.createEntity();
athmosphere.edit()
.add(new MapModelComponentArtemis(assets.Athmosphere));
.add(new PositionComponentArtemis(1,2,3)) //for example
//.add(new BoundsComponent(G.CELL_SIZE,G.CELL_SIZE)).getEntity();
return athmosphere;
}
我为另一个示例播放器实体创建了
public static Entity createMPlayer() {
Entity Mplayer = GameWorld.world.createEntity();
Mplayer.edit()
.add(new AnimationComponentArtemis())
.add(new PhysicsComponent())
.add(new ModelComponentArtemis(assets.PlayerM))
.add(new HealthComponent(PlayerComponentArtemis.lifepoints))
.add(new ManaComponent(PlayerComponentArtemis.manapoints))
.add(new EnergyComponent(PlayerComponentArtemis.enerGpoints))
.add(new xpcomponent(PlayerComponentArtemis.exppoints))
.add(new LevelComponent(PlayerComponentArtemis.level))
.add(new NameComponent(PlayerComponentArtemis.name))
.add(new RespawnOnDeath());
.add(new Gravity())
.add(new PositionComponentArtemis(1,3)) //for example
//.add(new WallSensor())
//.add(new Wallet(12))
//.add(new PlayerControlled())
//.add(new BoundsComponent(G.CELL_SIZE,G.CELL_SIZE)).getEntity();
return Mplayer;
}
在我的EntitySpawnerSystem中,上述方法的调用方式如下:
public void spawnEntity(float x,float y,float z,String entity) {
switch (entity) {
case "athmosphere":
createAthmosphere(x,y,z);
break;
case "apprenticeMap":
createApprenticeMap(x,z);
break;
case "player":
assemblePlayer(x,z);
break;
case "scorpion1":
spawnScorpion0(x,z);
break;
default:
throw new RuntimeException("No idea how to spawn entity of type " + entity);
}
}
煽动他人
private void assemblePlayer(float x,float z) {
if (CreationUi.Sexe == "M"){
player = EntityFactoryArtemis.createMPlayer();
groupManager.add(player,"player-friend");
giveWeapon(player,"sword");
tagManager.register("player",player);
//combatSystem.respawnEntity(player);
InventoryComponent inventory = new InventoryComponent();
player.edit().add(inventory);
return;
}
if (CreationUi.Sexe == "F"){
player = EntityFactoryArtemis.createFPlayer();
groupManager.add(player,player);
//combatSystem.respawnEntity(player);
InventoryComponent inventory = new InventoryComponent();
player.edit().add(inventory);
return;
}
// Now create a drone that will swerve towards the tracker which contains the camera. this will create a smooth moving camera.
world.createEntity()
.edit()
.add(new PositionComponentArtemis(-37f,76f,-175.83f))
.add(new PhysicsComponent())
//.add(new Homing(midpoint))
.add(new Camera()).getEntity();
}
public static Entity getPlayer() {
return player;
}
private void createAthmosphere(float x,float z) {
Entity athmosphere = MapFactoryArtemis.createAthmosphere();
groupManager.add(athmosphere,"map");
tagManager.register("map",athmosphere);
return;
}
private void createApprenticeMap(float x,float z) {
Entity apprentice = MapFactoryArtemis.createApprentice();
groupManager.add(apprentice,apprentice);
return;
}
举个例子,假设我的MapRenderSystem:
@All({MapModelComponentArtemis.class})
public class MapRenderSystem extends EntitySystem {
public OxyddiA game;
private static final float FOV = 67F;
private final PerspectiveCamera perspectiveCamera;
private final PerspectiveCamera weaponCamera;
public final Environment environment;
public final ModelBatch batch;
private Entity weapon;
public float delta;
public Vector3 position;
ComponentMapper<MapModelComponentArtemis> mm;
ModelInstance mInst;
public MapRenderSystem() {
super(Aspect.all(MapModelComponentArtemis.class));
batch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight,0.8f,1f));
perspectiveCamera = new PerspectiveCamera(FOV,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
perspectiveCamera.near = 0.1f;
perspectiveCamera.far = 3000f;
weaponCamera = new PerspectiveCamera(FOV,Gdx.graphics.getHeight());
weaponCamera.near = 0.1f;
weaponCamera.far = 20f;
}
@Override
protected boolean checkProcessing() {
return true;
}
public void resize(int width,int height) {
perspectiveCamera.viewportHeight = height;
perspectiveCamera.viewportWidth = width;
}
protected void processEntities(ImmutableBag<Entity> entities) {
for (int i = 0; i < entities.size(); i++) {
MapModelComponentArtemis mod = entities.get(i).getComponent(MapModelComponentArtemis.class);
mInst = mod.getModelInstance();
batch.begin(perspectiveCamera);
batch.render(mInst,environment);
batch.end();
}
}
@Override
protected void processSystem() {
if(checkProcessing()) {
begin();
processEntities(getEntities());
end();
}
}
}
我的MapComponent:
public class MapModelComponentArtemis extends Component {
@Wire
public Model model;
public ModelInstance instance;
private boolean isVisible = false;
public MapModelComponentArtemis(){}
public MapModelComponentArtemis(Model model,float x,float z) {
this.model = model;
instance = new ModelInstance(model);
}
public MapModelComponentArtemis(Model model) {
this.model = model;
}
public Model getModel() {
return model;
}
public void setModel(Model model) {
this.model = model;
}
public void setModelInstance(Model model,ModelInstance modelInstance){
this.instance = new ModelInstance(model);
}
public ModelInstance getModelInstance() {
return instance;
}
public void setMeshView(ModelInstance modelInstance) {
this.instance = modelInstance;
}
public boolean isVisible() {
return isVisible;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
}
是的,太烂了,等等,但是我需要一个结果:P 任何帮助将是很多非常感谢的:)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)