Note that there are some explanatory texts on larger screens.

plurals
  1. POAS3: Model and View Communication in a Game
    primarykey
    data
    text
    <p>So I'm attempting to use the MVC pattern for a game I'm working on. Everything has been going pretty smoothly so far, but I'm having trouble figuring out how to get my model and my view to talk to each other effectively.</p> <p>My general model structure involves lots of nested information.</p> <pre><code>a Level has Rooms a Room have Layers a Layer has Objects </code></pre> <p>Each layer has an index and a corresponding layer in the view that is rendering it. I need the objects to post an update message as they animate so it's corresponding layer in the view can update. I'm trying to use the built in event system to handle these updates.</p> <p>My issue is I'm not sure how to avoid putting listeners on every object in the game - which strikes me as bad ( perhaps I'm wrong here ). If I change the rooms, the layer doesn't have a way of removing listeners from the objects in the last room because it only accesses layers through the current room. Objects are only updated when they are in the current room, so the other objects won't need to fire events.</p> <p>The view is set up to cascade events to all of the children, so the root node can receive all updates ( I think I did that part correctly ), and the layer can match the target because it knows which layer it's rendering. The problem is getting the message out from the objects to the view.</p> <p>Of course this makes sense to me, because I've been working with the code for a while now.</p> <p>If I can provide more clarification please ask. This is my first time working with the MVC pattern, so I'm sure I could do things better.</p> <p>If you have any suggestions as to how I might solve this conundrum, please share!</p> <p><strong>Edit:</strong> I have something working keeping track of the current layerset from outside of the view and the model which manages adding/removing the appropriate event listeners and delegating the update event to the layer as suggested. But please, anything I can do to improve this please do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload