Game Development Reference
In-Depth Information
It literally means “not.” When used with Boolean values, it means “the opposite value of.” You can put
the jkp operator in front of any Boolean value to read it as its opposite value. Let's use the jkp opera-
tor in the kjReoe^ehepu>qppkj?he_g event handler to turn the visibility button into a toggle button:
1. Modify the directive in the kjReoe^ehepu>qppkj?he_g event handler so that it looks like the
following:
bqj_pekjkjReoe^ehepu>qppkj?he_g$arajp6IkqoaArajp%6rke`
w
dehhL]ca*_]p*reoe^ha9 dehhL]ca*_]p*reoe^ha 7
y
2. Save the I]ej*]o file and test the project.
3. Click the visibility button a few times. You should see the cat appear and disappear each time
you click it.
The value that you've given the reoe^ha property in the previous directive is this:
dehhL]ca*_]p*reoe^ha7
It literally means “the opposite of the cat's current visibility state.” If the cat's current visibility state is
pnqa, the opposite state will be b]hoa. And if it's b]hoa, the state will be read as pnqa.
When the program first runs, the cat is (obviously) visible. Its reoe^ha property is pnqa. When the
visibility button is clicked, the program therefore reads dehhL]ca*_]p*reoe^ha as b]hoa. The second
time the button is clicked, the cat's visibility is now b]hoa, so the program reads dehhL]ca*_]p*reoe^ha
as pnqa.
The beauty of using the jkp operator in this way is that you never need to know whether the cat's
visibility property is pnqa or b]hoa. The program keeps track of this for you. And you need only one
button to toggle between these two states.
You can use this feature of the not operator to toggle between two states with any variables or prop-
erties that accept Boolean values. Boolean values are extremely useful in game design for keeping
track of things such as whether enemies are dead or alive, whether items have been picked up or not,
and whether doors are locked or unlocked. Wherever you use Boolean values, you'll probably find
a clever use for the not operator, like you've used it here.
Having a look
The next thing you'll do is make a button that lets the cat look around at the bright and beautiful
world around it. But before you're able to do this, you need to make sure that the _]p object is set up
properly so that its eyes are independent objects that you can control with code:
1. In the opknu>kkg*bh] file, double-click the ?]p symbol in the Library to enter symbol editing
mode.
2. Click one of the cat's eyes and delete it. (The pupil and white of the cat's eye are actually sepa-
rate shapes, so you'll need to double-click the eye to select both shapes together.) You should
now have a one-eyed cat, as shown in Figure 4-12.
 
Search Nedrilad ::




Custom Search