Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why I cannot recreate entity after removing entity from the engine? #235

Open
ronjunevaldoz opened this issue Jul 18, 2016 · 2 comments
Open
Labels

Comments

@ronjunevaldoz
Copy link

ronjunevaldoz commented Jul 18, 2016

In this below code method, I've tested creating and removing entity, because I'm planning to create bullet pool this way.

 public void build () {
        Entity bulletTest1 = createBullet(0,0);   // works perfectly but
        removeEntity(bulletTest1); // after engine remove this bulletTest1 entity then
        Entity bulletTest2 = createBullet(0,0); // recreate it, it doesn't work anymore 
 }

In this below code example I've create a BulletFactory that creates bullet entity made from engine.

 public Entity createBullet(float x, float y) {
    Entity entity = createEntity(Constants.Flags.BULLET);

    BulletComponent bullet = engine.createComponent(BulletComponent.class);
    SizeComponent size = engine.createComponent(SizeComponent.class);
    TextureComponent texture = engine.createComponent(TextureComponent.class);
    PhysicsComponent physics = engine.createComponent(PhysicsComponent.class);
    TransformComponent transform = engine.createComponent(TransformComponent.class);
    MovementComponent movement = engine.createComponent(MovementComponent.class);

    texture.region = GameAssets.cannonball;
    transform.position.set(x, y);
    size.width = 0.25f;
    size.height = 0.25f;
    transform.origin.set(size.width / 2, size.height /2);
    float bodyPosX = transform.position.x + transform.origin.x;
    float bodyPosY = transform.position.y +  transform.origin.y;
    physics.body = createBulletBody(entity, bodyPosX, bodyPosY);

    entity.add(bullet);
    entity.add(size);
    entity.add(texture);
    entity.add(physics);
    entity.add(transform);
    entity.add(movement);

    engine.addEntity(entity);
    return entity;
}

public Entity createEntity(Constants.Flags flag) {
    Entity e = engine.createEntity();
    e.flags = flag.ordinal();
    return e;
}
@dsaltares
Copy link
Member

Could you please define "it doesn't work anymore"? I couldn't possibly know what the problem is.

Also, if you think this is a bug, could you please write a failing jUnit test so we can reproduce and fix the issue?

@ronjunevaldoz
Copy link
Author

The "it doesn't work anymore" means on the second creation of bullet, there's no texture and body created ,so I assume it doesn't work. Let me try the failing jUnit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants