I have two cases, so far, where I find myself needing to access methods/properties of a parent from a child.
Right now I have the EntityManager in my Scene.
In my levels (loaded using Loader, as per the examples), I’m finding myself doing
the_thing = parent.parent.entityManger.getEntityById(somthing_id)
whenever I need to get an entity to operate on.
This is because the parent of the level is the Loader, and what’s needed is the Scene that contains the loader.
This is particularly bad because it means the level _has to be_ called from a Loader, it can’t be loaded direct into a Scene (since parent.parent would not be the right thing)
Similarly, in game-objects I find myself needing to call on functions in the level. Here is a platform that disappears a while after it is created. It needs to tell the level that it is gone:
EntityBase {
entityId: "startPlatform"
entityType: "platform"
//...
Timer {
interval: 3000
running: true
onTriggered: {
parent.parent.removePlatform(entityId)
removeEntity()
}
}
How can I avoid this nasty “parent.parent” thing?
I can see that in the case of removing the platform, this could be a signal, since no return value is required, but how about the first case?
-
This topic was modified 8 years, 5 months ago by
GreenAsJade.