Best practices for the UpdateEvent

26 views
Skip to first unread message

Alex

unread,
Apr 22, 2014, 12:10:46 AM4/22/14
to excal...@googlegroups.com
I was wondering what the purpose is for having separate `update` events on different objects. Both the Engine and Actor allow you to respond to an update event, but couldn't you really just handle all of your logic within the Engine.update function?

I'm guessing the reason each separate update exists is for organization's sake, but was also wondering if there are any relation between the different instances. For example, does Engine.update always before any of the individual Actor.update method?

Erik Onarheim

unread,
Apr 22, 2014, 8:41:00 AM4/22/14
to excal...@googlegroups.com
You are correct, having an update event fire on both Engine and Actor is more helpful for code organization and separation of concerns. It would indeed be possible to handle all your logic in the engine update function. 

Generally updates off of an actor should be related to that specific actor, and updates off the engine should be related to the engine. For example, useful things to put in the engine update might but updating a score or health bar off of some state, or perhaps conditions for a scene transition. 

Technically the engine 'update' will fire after all of the actor 'update' events are complete for an update cycle, the event is emitted at the end of the Engine.update, and the Actor.update methods. Although I would probably recommend against relying on the timing of 'update' events to perform any game specific logic. Currently Excalibur events are processed off a queue at the beginning of the next mainloop before anything else, this means all Engine events will be processed before all Actor events. So the engine event callbacks will fire before the actor ones. Maybe this needs to be changed/thought about more in excalibur?

Alex

unread,
Apr 22, 2014, 11:32:19 PM4/22/14
to excal...@googlegroups.com
Yes, I agree with you that "relying on the timing of 'update' events to perform any game specific logic" is a bad idea. My question was simply out of curiosity and to double check that I'm not missing any important concepts related to how things are organized.
Reply all
Reply to author
Forward
0 new messages