XNA - Codeschnipsel - Move_Background

Webdesigner's
Verfügbare Informationen zu "XNA - Codeschnipsel - Move_Background"

  • Qualität des Beitrags: 0 Sterne
  • Beteiligte Poster: Snowball
  • Forum: Webdesigner's
  • Forenbeschreibung: Das Hilfe Forum für alle Webdesigner
  • aus dem Unterforum: C# XNA
  • Antworten: 1
  • Forum gestartet am: Freitag 20.07.2007
  • Sprache: deutsch
  • Link zum Originaltopic: XNA - Codeschnipsel - Move_Background
  • Letzte Antwort: vor 16 Jahren, 5 Monaten, 30 Tagen, 22 Stunden, 42 Minuten
  • Alle Beiträge und Antworten zu "XNA - Codeschnipsel - Move_Background"

    Re: XNA - Codeschnipsel - Move_Background

    Snowball - 28.10.2007, 01:26

    XNA - Codeschnipsel - Move_Background
    Die folgende Anwendung bewegt ein Bild über den Bildschirm, wenn man die Pfeiltasten drückt.

    Code: #region Using Statements
    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Storage;
    #endregion

    namespace x8
    {
        /// <summary>
        /// This is the main type for your game
        /// </summary>
        public class Game1 : Microsoft.Xna.Framework.Game
        {
            GraphicsDeviceManager graphics;
            ContentManager content;
            KeyboardState ksState;

            // Variablen für Geschwindigkeit des Logos bzw. Sprites
            int hSpeed = 10;
            int vSpeed = 10;

            Vector2 spritePosition = Vector2.Zero;
            // Das Texture-Objekt, das wir verwenden
            Texture2D myTexture;

            // Die aktuellen Koordinaten des Logos bzw. Sprites
           

            // Das SpriteBatch-Objekt, welches wir zum Zeichnen des Sprites verwenden
            SpriteBatch spriteBatch;

            public Game1()
            {
                graphics = new GraphicsDeviceManager(this);
                content = new ContentManager(this.Services);

                graphics.IsFullScreen = true;

            }


            /// <summary>
            /// Allows the game to perform any initialization it needs to before starting to run.
            /// This is where it can query for any required services and load any non-graphic
            /// related content.  Calling base.Initialize will enumerate through any components
            /// and initialize them as well.
            /// </summary>
            protected override void Initialize()
            {
                // TODO: Add your initialization logic here

                base.Initialize();
            }


            /// <summary>
            /// Load your graphics content.  If loadAllContent is true, you should
            /// load content from both ResourceManagementMode pools.  Otherwise, just
            /// load ResourceManagementMode.Manual content.
            /// </summary>
            /// <param name="loadAllContent">Which type of content to load.</param>
            protected override void LoadGraphicsContent(bool loadAllContent)
            {
                if (loadAllContent)
                {
                    this.myTexture = Texture2D.FromFile(this.graphics.GraphicsDevice,
                      "EvoXTexture.bmp");
                    this.spriteBatch = new SpriteBatch(this.graphics.GraphicsDevice);
                    this.IsMouseVisible = true;
                }

                // TODO: Load any ResourceManagementMode.Manual content
            }


            /// <summary>
            /// Unload your graphics content.  If unloadAllContent is true, you should
            /// unload content from both ResourceManagementMode pools.  Otherwise, just
            /// unload ResourceManagementMode.Manual content.  Manual content will get
            /// Disposed by the GraphicsDevice during a Reset.
            /// </summary>
            /// <param name="unloadAllContent">Which type of content to unload.</param>
            protected override void UnloadGraphicsContent(bool unloadAllContent)
            {
                if (unloadAllContent == true)
                {
                    this.content.Unload();
                }
            }


            /// <summary>
            /// Allows the game to run logic such as updating the world,
            /// checking for collisions, gathering input and playing audio.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
            protected override void Update(GameTime gameTime)
            {
               
                ksState = Keyboard.GetState();

                if (ksState.IsKeyDown(Keys.Up))
                {


                    this.spritePosition.Y += this.vSpeed;

                }

                if (ksState.IsKeyDown(Keys.Down))
                {


                    this.spritePosition.Y -= this.vSpeed;

                }

                if (ksState.IsKeyDown(Keys.Left))
                {
                   

                    this.spritePosition.X += this.hSpeed;

                }

                if (ksState.IsKeyDown(Keys.Right))
                {
                   

                    this.spritePosition.X -= this.hSpeed;
                   
                }

                if (ksState.IsKeyDown(Keys.Escape))
                {
                    this.Exit();
                }

                // Allows the default game to exit on Xbox 360 and Windows
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                    this.Exit();

                base.Update(gameTime);
            }


            /// <summary>
            /// This is called when the game should draw itself.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
            protected override void Draw(GameTime gameTime)
            {
                this.graphics.GraphicsDevice.Clear(Color.White);

                this.spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
                this.spriteBatch.Draw(this.myTexture, this.spritePosition, Color.White);
                this.spriteBatch.End();

                base.Draw(gameTime);
            }
        }
    }

    Viel Spaß damit :)



    Mit folgendem Code, können Sie den Beitrag ganz bequem auf ihrer Homepage verlinken



    Weitere Beiträge aus dem Forum Webdesigner's

    XNA - Codeschnipsel - Tilemap bewegen - gepostet von Snowball am Donnerstag 01.11.2007
    WinAPI - Texte im Child-fenster anzeigen - gepostet von Snowball am Dienstag 24.07.2007



    Ähnliche Beiträge wie "XNA - Codeschnipsel - Move_Background"

    Kaila - Move - dEnIz (Sonntag 19.11.2006)
    please move along - Anonymous (Sonntag 23.01.2005)
    Faith Can Move A Mountain - vanessa (Freitag 06.10.2006)
    PHADE_Background_V_1_0 - Butcher (Donnerstag 21.09.2006)
    Historical Background/Physical Geography (4-5.10.06) - *SoulFire* (Samstag 07.10.2006)
    Lieblings Move der WWE - batista (Donnerstag 01.12.2005)
    G-Move 2007 - Jan Schumann (Sonntag 25.03.2007)
    Donnerstag 08. Dezember 2005 im Move Club - Chris (Montag 05.12.2005)
    Neuer Background Allypage - Red Beast (Freitag 20.04.2007)
    1x11 Die Grosse Suche (Move On) - fallenangel (Sonntag 08.10.2006)