This tutorial concentrates on illustrating working with
for controlling the visibility (membership with AutoDrawSet) of any related set of primitives, and on
Logical entity for
for the purpose of showing/hiding these Primitives.
As a programmer you are responsible for ensuring each Primitive belongs to at most one PrimitiveSet.
Random number utilities:
randomness is a convenient tool for many
interactive graphical applications. XNACS1Lib supports random number
1. Obtain the example code
Here is the zip file to the source
files and compiled executable of this example.
Download and unzip the zip file and you will see an ExampleProgram folder. Open the ExampleProgram
folder, the EXE folder contains the compiled program and you can double click on the .sln
file to work with the source code.
If you double click and run the executable program, you will observe:
This application is almost identical to that from the second tutorial, except
two important points:
Button-X: hides/un-hides the ladder and the pink-ish circle.
Random speed of the soccer ball after each collision with the ladder.
In this tutorial, we will examine the details of implementing these
2. The Source Code Files/Structure
Take a look
folder that you have unzipped and you will see a
structure identical to that of previous tutorials. Once again, you can double
click on the
file to launch the IDE, we will concentrate on the
file where all the relevant source code are
3. Examine Game1.cs Structure:
When you open the
file in the IDE, you will see source code
structure that is very similar to that of the second tutorial:
Reference to libraries ?
Once again, we will examine each of :
in details and understand how
to implement the behaviors we have observed.
4. Examine Instance Variables of Game1.cs
When you expand the
region, you will observe:
A B C D
that are identical to previous tutorial ...
// E. Button-X click makes this set invisible
// Records if
the set is currently visible
The five sets of instance variables: A to E where variable sets A to D are
identical to previous tutorial.
) is a logical set
that lets us insert related Primitives and control the visibility of the
Primitives as a set.
5. Examine InitializeWorld() function of Game1.cs
function is once again very similar to previous
// A. Create the initialize the rotating
// B. Create and initialize the bouncing
// C. Create and initialize the cicle
controlled by the right thumb stick
// D. Create and initialize the eraser
// E. Insert: RightThumbCircle,
and Ladder into the m_VisibleSet
, after allocating the memory for the
inserted the RightThumbCircle and the RotatingLadder to be members of the
, and record the fact that current the
visible by setting
e to true.
6. Examine UpdateWorld() function of Game1.cs
Now in the UpdateWorld() function, we control the visibility of the
and the speed of the soccer ball after collision:
Update the Rotating ladder
toggle VisibleSet by the X-Button
m_SetIsVisible = !m_SetIsVisible;
Collide the soccer with the rotating ladder
m_SoccerBall.VelocityDirection = m_SoccerBall.Center -
m_SoccerBall.Speed = SPEED *
When the X-Button is clicked, we check if
, if so, we "RemoveAllFromAutoDrawSet()"
to hide the RightThumbCircle and the Ladder. Otherwise we call "AddAllToAutoDrawSet()"
to show the two primitives.
When collision between the soccer and the ladder is
detected, the speed of the soccer is
by the "RandomFloat()"