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

Do somebody tell me a best nano engineering book for beginners?
s. Reply
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
I'm interested in Nanotube
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
can nanotechnology change the direction of the face of the world
Prasenjit Reply
At high concentrations (>0.01 M), the relation between absorptivity coefficient and absorbance is no longer linear. This is due to the electrostatic interactions between the quantum dots in close proximity. If the concentration of the solution is high, another effect that is seen is the scattering of light from the large number of quantum dots. This assumption only works at low concentrations of the analyte. Presence of stray light.
Ali Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
QuizOver.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?