<< Chapter < Page
  Xna game studio     Page 6 / 9
Chapter >> Page >

Draw new material every 83 milliseconds

The code in Listing 6 causes the sprites to be drawn sixty times per second, but new material is drawn only once every msPerFrame milliseconds. The value for msPerFrame is set to 83 milliseconds in Listing 1 , but as you learned in an earlier module, its value could be changed by program code as the program is running.

Therefore, in this program, new material is drawn 30 times per second. Every other frame that is drawn looks exactly like the one before it, but the humaneye is not fast enough to be able to detect that.

Apply dynamic scaling to the background image

A different and ever increasing scale factor is applied to the background image each time the body of the if statement in the Update method in Listing 6 is executed.

Two components in the scale factor

This overall scale factor is composed of the fixed backgroundBaseScale factor computed in Listing 5 and a dynamic scale factor named dynamicScale that is computed in Listing 7 .

An optical illusion

This is what causes the size of the planet to continue to increase during the animation sequence creating the illusion that the UFO is getting closer to thesurface of the planet.

The dynamic portion of the overall scale factor

The value of the dynamic portion of the overall scale factor increases by 0.03 each time this code is executed. Once the dynamic portion reaches a valueof 10, it is reset to zero and the animation sequence plays again from the beginning.

This is accomplished by the scaling algorithm shown in Listing 7 .

Listing 7 . Apply dynamic scaling to the background image.

//Reset the animation if the dynamicScale factor // is greater than 10.if(dynamicScale>10) { dynamicScale = 0.0f;} else { //Increase the dynamicScale factor and use it// to compute a new scale factor that will be // applied to the background image in the next// call to the Draw method. dynamicScale += 0.03f;backgroundScale = backgroundBaseScale * (1 + dynamicScale);}//end if-else on dynamicScale

Changing the origin of the background image

The SpriteBatch.Draw method has one parameter named position and another parameter named origin . You can cause the origin to be any point in the image relative to its upper left corner.

Important: The position parameter specifies the position in the game window where the image's origin will be drawn.

If you hold the position parameter constant and vary the origin , the image will appear to slide around within the game window.

Increasing the scale alone is insufficient

Consider the background image shown in Figure 3 . Assume that the origin of the image is the upper left corner of the image. Also assume that the image will be drawn with that origin in the upper left corner of the game window.

If we were to scale the image to make it larger, the planet would be pushed down and to the right and would exit the game window near the bottom rightcorner of the game window. That is not what we are looking for.

Need to stabilize the location of the planet in the game window

To achieve the effect we are looking for, we need to cause the planet to remain in pretty much the same location within the game window as it getslarger. One way to accomplish that is by causing the origin to move down and to the right within the background image as the planet becomes larger. (Obviouslythat is not the only way to accomplish it.)

Questions & Answers

breathing in reptiles
sam Reply
which molecules binds to the active site of an enzyme
Ghulam Reply
what is nutrients
Patrick Reply
nutrients is substance which body use in terms of need
can I join?
substance that provides nourishment essential for the maintenance of life and for growth.
right same answer as you Umar
please remind me
Any material that provide essential components for cell metabolisms is nutrient
what are the types of skeleton
Tanyi Reply
endo skeleton and exo skeleton
or types of skeletons There is exo skeleton found in class insecta Exo skeleton found in phylum chordata and lastly hydrostatic skeleton found mainly in earth worms
and hydrostatic skeleton
what is life?
Jerson Reply
life is when any living thing breath or respirate.
I want to join
me too
me two
me too
me too
I here
Does anybody knows another biology app that brings good understand
give an example of a phylum where all members have open circulatory
Omoro Reply
phylum Anthropoda
how do u change the unit of temperature from degree celsius to degree Fahrenheit
what are beneficial effects in industrial
Nnamani Reply
create employment
provide food
dirty the environment
pollution and lack of knowledge about how to manage waste
what is gametophyte
Ibrahim Reply
what is biology
Basiru Reply
Biology deals with the study of living organisms and their interactions with each other and the environment.
biology simply means the study of living and non-livingthings.
what is the meaning of ubiquitous
Hamziyatu Reply
Under what topic is this question
three branches of biology
Alexander Reply
what is the cell
Olajide Reply
what is life
cell is the functional and structural unit of life
life is a problem solving entity
what is the characteristics of plant cell
Describe the process that results in the formation of a tetrad.
Michael Reply
what is biology
Ndukwe Reply
biology is the study of life
what is biology
Jimmy Reply
the study of life
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Xna game studio. OpenStax CNX. Feb 28, 2014 Download for free at https://legacy.cnx.org/content/col11634/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Xna game studio' conversation and receive update notifications?