Game Development Reference
In-Depth Information
Figure 22-3. What happens when you click the left arrow?
The outcome of this question depends on the order in which input is handled for each game object.
If the penguin handles the input before the penguin selector, then the penguin selector will move to
the other penguin. If the selector's handleInput method is called first, then the selected penguin will
move to the left. Generally, when you develop programs, you want to be in control of the program's
behavior. This means you have to choose in which order you want to handle the input and make sure
it always happens that way. In this case, the desired behavior is that the selected penguin moves to
the left. And as a general rule, you would like objects that are drawn on top to handle input first . In
other words, you need to call the handleInput method on the objects in the list in reverse order of
the order in which they're drawn. This can easily be done with the following for instruction, which
you put in the GameObjectList.handleInput method body:
GameObjectList.prototype.handleInput = function (delta) {
for (var i = this._gameObjects.length - 1; i >=0; i--)
this._gameObjects[i].handleInput(delta);
};
As a result, objects that are drawn on top now handle input first. Again, this illustrates how important
it is to get details like this right when specifying the player interface. An interface that isn't intuitive to
the player will very quickly lead to frustration—and the player may no longer want to play your game
because of issues with the interface.
 
Search WWH ::




Custom Search