Game Development Reference
In-Depth Information
Figure 13-12 . Add if() statement logic to exclude processing of nested if-else hierarchy if down or up keys being
pressed
The reason that I'm doing this is because when either the up or down key is being
pressed, the jump (or fly) or preparing to land sprite cel image is showing. For this
reason, optimization dictates that I need to turn off all of the “alternating between sprite
cel 1 and sprite cel 2” processing code. I want to do this so that this constant processing
is not going on in memory and in the thread (CPU) when the imageStates(1) and im-
ageStates(2) are not even being used (displayed) inside of the spriteFrame ImageView
“container.”
To achieve this optimization objective, I added a new level of evaluation to the out-
side of the second nested if() loop. This is the level that contains all of the sprite cel
changes (1 to 2 and back) using the animator, framecounter, and runningspeed vari-
ables and related processing. This new more complex evaluation statement guarantees
that all of this run-cycle processing logic will not be executed if this the new condition
is being met.
What this new condition says specifically, is that if the animator variable is false
AND the up AND down keys are both not being used (are false) then to process the
rest of the logic, which switches between the two sprite image states (as well as waiting
a certain number of pulse events before each switch). What this means is that if either
of the up or down keys are being pressed (thus showing the fly or land sprite cel image
state), none of the programming logic past that point will be processed at all, saving
 
Search WWH ::




Custom Search