Game Development Reference
In-Depth Information
12. Save the I]ej*]o file.
13. Test the project. You should now be able to click the back to start buttons in both pages to
return you to the first page of the storybook.
It should be fairly obvious by now what the new code does. You've added new event listeners to the
buttons in the lkj`L]ca and dehhL]ca instances and then wrote event handlers that displayed and
removed the appropriate page.
Knowing when to use this model
As a model for creating your own interactive movies, the simple system you used here has a number
of advantages:
It's understandable : the relationship between the objects, event listeners, and methods is very
clear. You can play with this model while gradually acquiring more confidence as a programmer.
And when you're ready to try something a little more daring, you can easily adapt it.
Only minimal programming skill is required : if you understand what you've written in this
sample program, making a much larger interactive movie with dozens of pages and buttons is
simply a question of doing more of the same. You don't need to know any more programming,
and what you lack in programming skill you can easily make up for in imagination. Copy/paste
will become your best friend!
It's easy to make changes to the program : if you want to change what the buttons do, you
just need to change the directives in the event handlers.
There is one glaring disadvantage, however. Imagine that you have hundreds of pages and hundreds of
buttons. You'll have a program that is thousands and thousands of lines of code long, and managing
all that could become a horrendous job.
For really big projects, you need a different strategy. You'll probably want to store information about
the pages and buttons in some sort of data storage system (such as in an array, which you'll look at
in Chapter 9) and then write a small handful of short-but-sweet methods that switch pages based on
context. You'll have much less code, and it would all be self-administrating. But you'll have to actually
know how to do this, and the programming skill and experience required are quite considerable. It's
a worthy project and it's one that you'll have the skills to attempt by the time you get to the end of
this topic.
One word of advice: make sure that whatever you program, you actually understand what you're
doing and why it works. A program that's 100 lines long and understandable is better than a super-
efficient 10-line program that does the same thing but which you don't understand. Don't feel any
pressure to write the most compact and elegant code. That will happen naturally as your skills and
confidence grow . . . and they will!
 
Search Nedrilad ::




Custom Search