mardi 25 septembre 2018

Using a Manager to manage game object lifetime

I have a lot of hint arrow requirements in my game. So far, i have a hint arrow manager, that checks the arrows kill condition, and destroys it if the kill condition is satisfied. The manager has an update function linked to the games update.

Is it okay practice to manage lifetime from the Manager?

Pseudo code example of my system:

HintArrowFactory:createHintArrow(target, angle, priorityEnum)
                :addKillCondition(time, function(obj, deltaTime) obj.time -= deltaTime))

Function definitions:

HintArrowFactory HintArrowFactory:CreateHintArrow(target, angle, priorityEnum)
HintArrowFactory HintArrowFactory:AddKillCondition(HintArrowAdditionalParams, KillConditionFunc)
bool KillConditionFunc(HintArrowObj, deltaTime)

Another approach would be to handle lifetime explicitly in the code: No inpure kill conditions, but possibly some extra strain when coding.

hint = createHint()
delayedDestroy(hint)

What would be advantages/disatvantages of either approach?

P.S

Using timing kill condition and delayed destroy is done just for convenience. Another example specific for my game would be destroy with message box. so the difference would be that in the first case i would send isMessageBoxActive kill condition, and in the second case i would have to make another update function to monitor msgbox activity and then destroy the arrow - destroyWithMessageBox(hintArrow).

Aucun commentaire:

Enregistrer un commentaire