我有更新/渲染机构(怪物)的性能问题,你可以从下面的照片看到,因为我增加内存(私人工作集)CPU增加了很多机构,例如,如果我添加100个机构随机移动地图merory(私人工作集)将达到900.000k发生了什么?我做错了什么? 图片网址:http://prntscr.com/7l31tn
Mob初始化 - >>
private void initializeEntityIntoWorld() {
//initializeTheMOb
BodyDef bodyDef = new BodyDef();
FixtureDef fixtureDef = new FixtureDef();
PolygonShape boxShape = new PolygonShape();
bodyDef.position.set(6,3);
bodyDef.type=BodyType.DynamicBody;
bodyDef.fixedRotation=true;
body = world.createBody(bodyDef);
body.setUserData(this);
boxShape.setAsBox(WIDTH_METER, HEIGHT_METER);
fixtureDef.shape=boxShape;
fixtureDef.filter.categoryBits = Constants.BIT_PLAYER;
fixtureDef.filter.maskBits = Constants.BIT_GROUND;
fixtureDef.density = 1;
fixtureDef.friction = 0f;
body.createFixture(fixtureDef).setUserData("Mob");
body.setGravityScale(0);
boxShape.dispose();
}
@Override
public void update(float deltatime) {
super.update(deltatime);
}
@Override
public void render(SpriteBatch batch) {
super.render(batch);
Sprite sprite = new Sprite(currentFrame);
sprite.setSize(WIDTH_METER*2,HEIGHT_METER*2);
sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
sprite.setPosition(body.getPosition().x-sprite.getOriginX(), body.getPosition().y-sprite.getOriginY());
sprite.draw(batch);
}
级别类更新/渲染所有主体
public void render(SpriteBatch batch){
for (Entity entity : dynamicEntitysDestroyed)
world.destroyBody(entity.getBody());
dynamicEntitysDestroyed.clear();
for(int i=0;i<dynamicEntitys.size;i++) dynamicEntitys.get(i).render(batch);
}
public void update(float deltatime){
for(int i=0;i<dynamicEntitys.size;i++){
Entity entity=dynamicEntitys.get(i);
if(entity.isRemoved())
dynamicEntitys.removeIndex(i);
else entity.update(deltatime);
}
}
public void addEntity(Entity entity){
dynamicEntitys.add(entity);
}
public void destroyEntity(Entity entity) {
dynamicEntitysDestroyed.add(entity);
}