Giter Site home page Giter Site logo

Comments (3)

dsaltares avatar dsaltares commented on May 19, 2024

You can always subscribe your EntitySystem to entity events with the Engine by implementing the EntityListener interface. However, the handler will be called every time any entity enters or leaves the engine.

You can always check whether the added/deleted entity is of interest by doing:

ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.getFor(...));
entities.contains(entity);

Would that be enough?

The EntitySystem class doesn't have an associated family. We could, maybe, add listeners to the engine on a per family basis.

from ashley.

chrisapril avatar chrisapril commented on May 19, 2024

Hi,

that wouldnt be enough. Another problem is that when the listener gets informed, i dont have access to the component anymore (when i have understood the ashley code right).

For example i am doing something like this very often:

BehaviourSystem .....

    @Override
    protected void removed(Entity e) {
        super.removed(e);

        Behaviour b = e.getComponent(BehaviourComponent.class).getBehaviour();
        Task task = b.getCurrentTask();
        if(task != null){
            task.removeApplicant(e);
        }
    }

or i a SteeringForceSystem:

@Override
    protected void removed(Entity e) {
        super.removed(e);

        if (spatialMapper.has(e)) {
            Spatial spatial = spatialMapper.get(e);
            spatial.vel.x = 0;
            spatial.vel.y = 0;
        }

        if (steeringForceMapper.has(e)) {
            SteeringForce sf = steeringForceMapper.get(e);
            sf.steeringForce.set(0, 0);
        }
    }

from ashley.

dsaltares avatar dsaltares commented on May 19, 2024

Added in f90d129

from ashley.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.