PBS-KIDS / Platypus

2D tile based game framework in HTML5
128 stars 30 forks source link

Handle Logic and Tick #15

Closed pleduc closed 10 years ago

pleduc commented 10 years ago

I'm trying to use a timer event in an entity and the timer is only updating 10 times. I've read that the timer listens for "handle-logic" calls. Handle-logic calls as I understand are passed when a child-entity is added or a "tick" is passed from the scene. This makes me think that the only "handle-logic" calls that are being passed to my entity are from child-entities being added. How do I pass consistent "tick" calls to my entity so I can get my timer working properly?

My entity is in a entity-container in an action-layer and the action-layer has a "logic-handler" in it.

Any help would be appreciated, Patrick

probityrules commented 10 years ago

handler-logic automatically fires "handle-logic" on all entities contained directly within the "action-layer" entity (or whichever entity it's attached to). If your entity with the timer component is contained inside another entity making it a layer deeper, you can tell the parent entity's entity-container to pass along certain events it's listening to in its JSON definition. For example:

{
    "id": "action-layer",
    "components": [
        {"type": "handler-logic"},
        {"type": "entity-container",
            "entities": [ // These entities (whether added here or included by Tiled) receive "handler-logic" events from the container "action-layer" entity since it has the `handler-logic` component.
                {
                    "id": "entity-containing-more-entities",
                    "components": [
                        {"type": "entity-container",
                            "entities": [ // These entities are a layer deeper and won't receive "handler-logic" events unless this particular event is listed to be passed to children entities.
                                {
                                    "id": "entity-that-needs-handle-logic-event",
                                    "components": [{"type": "logic-component"}]
                                }
                            ],
                            "childEvents": ["handle-logic"] // so here is where we do that to give this `entity-container` component a list of events to pass along to its children.
                        }
                    ]
                }
            ]
        }
    ]
}

Does that answer your question? Or are you experiencing another issue?