Ok, an empty cartoon is
easy. But can we make a cartoon which does something. Sure! Here is an
example of simple cartoon displaying text "Hello World" for one second:
void Scene1 ()
// declare a text
Text MyText ( "Hello
// make it visible
Let's look more closely on this example. The lines beginning with // are
just comments. A comment
is a bit of English text that you can put in the middle of a program,
usually to explain what the program does. When the compiler sees a //,
it ignores everything from there until the end of the line. The 2 lines
beginning with // do nothing – but are very useful for understanding
the operation or the program. Good programming technique makes liberal
use of comments.
The following line:
Text MyText ( "Hello World" );
is our first real statement. First word
indicates that there will be a text object
in our scene. What is an object? Imagine you making a real movie and
you want to shoot a table, a chair, a car or something else in your
movie. These are all objects! When you are making an animated cartoon,
the line of text is also an object. You can do something with objects.
You can move a table, sit on a chair or drive a car… You can even drive
your car away from camera! You can also do a lot of things with a text
object in an animated cartoon. You can make text visible and invisible,
you can move, scale and rotate it and do other stuff. You will learn
how to do this later.
is a unique name
for your object. For example if you shoot a movie you may have 2 chairs
in front of your camera. And if you want an actor to sit on a chair you
will need to specify on which one. You should say something like "Sit
on the left chair please".
is something similar to "left chair". You may have many text objects in
your scene and if you want to do something with one of them then you
need a way to specify with which one. Word
(this could actually be almost any other word) will be used later to
work with the text object.
The text inside
parentheses indicates parameters of your text object. It this case this
is just a text to display. As you will see later, this is a
and it must be enclosed in double quotes by C++ standard.
The sentence, like most of the C++ sentences, is terminated with a
semi-colons and non-matching braces or brackets are probably the two
most common syntax errors made when first writing a program.
The next line
MyText.SetVisible ( true );
is also a statement. You already know that
is the name of a text object. A dot after an object name in this case
means that an instruction of what to do with an object will follow.
Such instruction is called method
. Different objects may have different methods for working with them.
The method name in our case is
. It has a parameter
inside parentheses. As we will see later this is a boolean (or
) variable which can be either
. If the parameter is
then we are going to make an object visible. If it is
then the object is going to be hidden. We use the method
to make our text object visible. By default all objects are invisible,
because most of the times you need to use only some of the objects in
your scene while other objects are hidden.
Note: The poor dot or
period (.), while not an operator (at least in C++) is one of the most
overloaded characters there is. (Overloading in general will be
discussed later.) It can be a sentence delimiter, the decimal point in
a floating point number or, as used in the above paragraph, part of the
“dot naming” convention. In general, that convention means the text to
the right of the dot is somehow associated with the object to the left
of the dot – either as a function operating on the object or as a
sub-object of the object.