iphpbb - Forenarchiv: Archivbeitrag des Forums Webdesigner's
Verfügbare Informationen zu "XNA - Codeschnipsel - Move_Background-2"

  • Qualität des Beitrags:
  • 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-2
  • Letzte Antwort: vor 1 Jahr, 25 Tagen, 15 Stunden, 7 Minuten
Alle Beiträge und Antworten
Snowball - 28.10.2007, 18:20
XNA - Codeschnipsel - Move_Background-2
Hier mal nen wenig komplexer:

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
{
 
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        KeyboardState ksState;

        SpriteBatch Sprite;
        SpriteFont Arial;

       
        int hSpeed = 10;
        int vSpeed = 10;

        Vector2 mousepos;
        Vector2 spritePosition = Vector2.Zero;
       
        Texture2D worldmap;
        Texture2D player;

     
        SpriteBatch spriteBatch;

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

            graphics.IsFullScreen = true;

        }


        protected override void Initialize()
        {
           
            base.Initialize();
        }


        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                this.worldmap = Texture2D.FromFile(this.graphics.GraphicsDevice,
                  "worldmap.bmp");
                this.player = Texture2D.FromFile(this.graphics.GraphicsDevice,
                  "player.bmp");
                this.spriteBatch = new SpriteBatch(this.graphics.GraphicsDevice);
                this.IsMouseVisible = true;
            }

            Arial = content.Load<SpriteFont>("Arial");
            Sprite = new SpriteBatch(graphics.GraphicsDevice);

           
        }


     
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent == true)
            {
                this.content.Unload();
            }
        }


        protected override void Update(GameTime gameTime)
        {

            MouseState mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                mousepos = new Vector2(mouse.X, mouse.Y);
            }

           
            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();
            }

         
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }


       
        protected override void Draw(GameTime gameTime)
        {
            this.graphics.GraphicsDevice.Clear(Color.White);

            this.spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            this.spriteBatch.Draw(this.worldmap, this.spritePosition, Color.White);
            this.spriteBatch.Draw(this.player, new Vector2(350, 200), Color.White);
            this.spriteBatch.End();

            Sprite.Begin();
            Sprite.DrawString(Arial, "Maus Position: " + mousepos, new Vector2(250, 285), Color.Green);
            Sprite.End();


            base.Draw(gameTime);
        }
    }
}
Mit folgendem Code, können Sie den Beitrag ganz bequem auf ihrer Homepage verlinken
Weitere Beiträge aus diesem Forum
Ähnliche Beiträge
warner bros move world - niki16 (Sonntag 25.07.2004)
Alle Background-Infos zu Schnappi, dem Krokodil - Klaubauter (Samstag 14.08.2004)
please move along - Anonymous (Sonntag 23.01.2005)
Amelia - I move on - RobGee (Samstag 18.06.2005)
Barthezz - On The MoVe 2005 (A1 + B1) - RobGee (Montag 11.07.2005)