i have a performance issue while i update/render bodies(Mobs) as you can see from the photo bellow as many bodies i add the memory(private working set) CPU increased for example if i add 100 bodies move random in the map the merory(private working set) will reach 900.000k what is going on? what i am doing wrong? IMAGE URL : http://prntscr.com/7l31tn
Mob initialization ->>
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);
}
Level class Update/Render All The bodies
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);
}