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

That effect is accomplished by the algorithm shown in Listing 8 .

Listing 8 . Adjust the origin for the background image.

//Also use the dynamicScale factor to compute a // new value for the origin of the background.// The origin is the point in the image that is // drawn at the point in the game window that is// passed as the second (position) parameter in // the call to the SpriteBatch.Draw method. This// has the effect of causing the background // image to slide up and to the left at the same// time that it is getting larger. spaceOrigin =new Vector2((float)(450 * (dynamicScale) / 12),(float)(338 * (dynamicScale) / 10)); }//end if on msElapsedbase.Update(gameTime); }//end Update

Examples

For example, in Figure 4 , the origin of the image (the point drawn in the upper left corner of the game window) was out in space far removed from theplanet. By Figure 10 the origin had shifted to the surface of the planet causing a point on the surface of the planet to be drawn in the upper left corner of thegame window. By Figure 12 , the origin had shifted all the way down and to the right to be on the surface of the ring that surrounds the planet.

The end of the Update method

Listing 8 signals the end of the overridden Update method.

The overridden Game.Draw method

To avoid confusion, I want to remind you that when programming in XNA, you override the Game.Draw method. Within that method, you make calls to the SpriteBatch.Draw method. These are entirely different methods belonging to different objects even though they have the samename.

No need to clear the game window

The overridden Game.Draw method begins in Listing 9 . Unlike the programs in earlier modules in this book, there is no need to clear thegame window to a constant color in this program because the background image of the planet completely fills the game window.

Two main sections of code

In this program, the overridden Game.Draw method consists of two main sections of code. The first section consists of a Begin , Draw , End sequence with alpha blending turned off. This code is used to draw the background image. Alpha blending is turnedoff to prevent any areas of the background image that may have a low alpha value or any green pixels from appearing to be transparent.

The second section consists of another Begin , Draw , End sequence with alpha blending turned on. This code is used to draw the UFO. Alphablending is turned on to cause the green areas in the UFO sprite shown in Figure 2 to be transparent and to let the background image show through.

Draw the background image showing the planet

The first major section of code is shown in Listing 9 .

Note the change that was made in the call to the SpriteBatch.Begin method to upgrade the program from XNA 3.1 to XNA 4.0.

Listing 9 . Beginning of the overridden Game.Draw method.

protected override void Draw(GameTime gameTime) { // Turn off blending to draw the planet in the// background. Note the update for XNA 4.0. // spriteBatch.Begin(SpriteBlendMode.None);spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque); //Draw the background.spriteBatch.Draw(spaceTexture,//sprite Vector2.Zero,//position re windownull,//rectangle Color.White,//tint0,//rotation spaceOrigin,//originbackgroundScale,//scale SpriteEffects.None,1.0f);//layer, near the back spriteBatch.End();

Questions & Answers

how do you get the 2/50
Abba Reply
number of sport play by 50 student construct discrete data
Aminu Reply
width of the frangebany leaves on how to write a introduction
Theresa Reply
Solve the mean of variance
Veronica Reply
Step 1: Find the mean. To find the mean, add up all the scores, then divide them by the number of scores. ... Step 2: Find each score's deviation from the mean. ... Step 3: Square each deviation from the mean. ... Step 4: Find the sum of squares. ... Step 5: Divide the sum of squares by n – 1 or N.
kenneth
what is error
Yakuba Reply
Is mistake done to something
Vutshila
Hy
anas
hy
What is the life teble
anas
hy
Jibrin
statistics is the analyzing of data
Tajudeen Reply
what is statics?
Zelalem Reply
how do you calculate mean
Gloria Reply
diveving the sum if all values
Shaynaynay
let A1,A2 and A3 events be independent,show that (A1)^c, (A2)^c and (A3)^c are independent?
Fisaye Reply
what is statistics
Akhisani Reply
data collected all over the world
Shaynaynay
construct a less than and more than table
Imad Reply
The sample of 16 students is taken. The average age in the sample was 22 years with astandard deviation of 6 years. Construct a 95% confidence interval for the age of the population.
Aschalew Reply
Bhartdarshan' is an internet-based travel agency wherein customer can see videos of the cities they plant to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400 a. what is the probability of getting more than 12,000 hits? b. what is the probability of getting fewer than 9,000 hits?
Akshay Reply
Bhartdarshan'is an internet-based travel agency wherein customer can see videos of the cities they plan to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400. a. What is the probability of getting more than 12,000 hits
Akshay
1
Bright
Sorry i want to learn more about this question
Bright
Someone help
Bright
a= 0.20233 b=0.3384
Sufiyan
a
Shaynaynay
How do I interpret level of significance?
Mohd Reply
It depends on your business problem or in Machine Learning you could use ROC- AUC cruve to decide the threshold value
Shivam
how skewness and kurtosis are used in statistics
Owen Reply
yes what is it
Taneeya
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