<< 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

the diagram of the digestive system
Assiatu Reply
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
what is cell divisoin?
Aron Reply
Diversity of living thing
ISCONT
what is cell division
Aron Reply
Cell division is the process by which a single cell divides into two or more daughter cells. It is a fundamental process in all living organisms and is essential for growth, development, and reproduction. Cell division can occur through either mitosis or meiosis.
AI-Robot
What is life?
Allison Reply
life is defined as any system capable of performing functions such as eating, metabolizing,excreting,breathing,moving,Growing,reproducing,and responding to external stimuli.
Mohamed
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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?

Ask