XNA, move the elves.

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingMicrosoft.Xna.Framework;usingMicrosoft.Xna.Framework.Audio;usingMicrosoft.Xna.Framework.Content;usingMicrosoft.Xna.Framework.GamerServices;usingMicrosoft.Xna.Framework.Graphics;usingMicrosoft.Xna.Framework.Input;usingMicrosoft.Xna.Framework.Media;namespacewindowsgame1{/// <summary>    ///This is the main type for your game/// </summary>     Public classGame1:Microsoft.Xna.Framework.Game {Graphicsdevicemanager graphics;        SpriteBatch SpriteBatch;        Texture2d texture;        Texture2d texturetransparent; Vector2 POS1=Vector2.zero; Vector2 Pos2=Vector2.zero; floatSpeed1 =2f; floatSpeed2 =3f;  PublicGame1 () {graphics=NewGraphicsdevicemanager ( This); Content.rootdirectory="Content"; }        /// <summary>        ///allows the game to perform any initialization it needs to before starting to run. ///This is the where it can query for any required services and load any non-graphic///related content. Calling base. Initialize'll enumerate through any///and initialize them as well. /// </summary>        protected Override voidInitialize () {//Todo:add Your initialization logic here            Base.        Initialize (); }        /// <summary>        ///loadcontent'll be called once per game and was the place to load///All of your content. /// </summary>        protected Override voidloadcontent () {//Create A new spritebatch, which can be used to draw textures.SpriteBatch =NewSpriteBatch (GraphicsDevice); //@ means ignore escape charactersTexture = content.load<texture2d> (@"Images/logo"); Texturetransparent= Content.load<texture2d> (@"Images/logo_trans"); //Todo:use this. Content to load your game content here        }        /// <summary>        ///unloadcontent'll be called once per game and was the place to unload///All content. /// </summary>        protected Override voidunloadcontent () {//todo:unload any non contentmanager content here        }        /// <summary>        ///allows the game to run logic such as updating,///checking for collisions, gathering input, and playing audio. /// </summary>        /// <param name= "GameTime" >provides a snapshot of timing values.</param>        protected Override voidUpdate (GameTime GameTime) {//allows the game to exit            if(Gamepad.getstate (Playerindex.one). Buttons.back = =buttonstate.pressed) This.            Exit (); //Todo:add Your update logic herePos1. X + =speed1; if(POS1. x>window.clientbounds.width-texture.width| |pos1. X<0) speed1*=-1; Pos2. Y+=Speed2; if(Pos2. Y > Window.clientbounds.height-texturetransparent.height | |Pos2. Y<0) Speed2*= -1; Base.        Update (GameTime); }        /// <summary>        ///This was called when the game should draw itself. /// </summary>        /// <param name= "GameTime" >provides a snapshot of timing values.</param>        protected Override voidDraw (GameTime GameTime) {graphicsdevice.clear (color.cornflowerblue); //Todo:add your drawing code here//notifies the video card to start transferring files//start drawing from the top left corner//White says no staining .Spritebatch.begin (); //Spritebatch.draw (texture, Vector2.zero, color.white);Spritebatch.draw (texture, POS1,NULL, Color.White,0, Vector2.zero,1, Spriteeffects.none,0); Spritebatch.draw (Texturetransparent, Pos2,NULL, Color.White,0, Vector2.zero,1, Spriteeffects.none,1);                        Spritebatch.end (); Base.        Draw (GameTime); }    }}

XNA, move the elves.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.