Multiple gotoAndPlay() considered harmful
When you are programming games (or all apps for that matter), one of the most important things is to make sure you maintain the states properly. By that I mean you do not want your game state to be in a state that you don't expect it to be. For instance, if your character is in running state, it shouldn't suddenly switch to hiding state without you knowing it.
Having multiple gotoAndPlay() in your code can corrupt your state very easily. It is like having the ability to modify a global variable anywhere you like, and it can create bugs that are hard to track down. Essentially, that's what gotoAndPlay() is -- it modifies the playhead info, and by using gotoAndPlay in more than one place, you have turned your playhead into a global variable.
It's for this reason that you should try to have only one place where gotoAndPlay() is called by putting it into a centralized function in your engine.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home