XNA programming
-
hallo
ich habe vor kurzem mit XNA Programming angefangen und da hab ich mal ne übung programmiert so wies in dem buch steht mit dem ich das lern... doch es scheint net zu funktionieren... hab das ganze auch schon genauestens verglichen und 3 mal nachprogrammiertusing System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace Übung2 { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public Texture2D BackroundGraphic; public Texture2D Quadrat; public Quadrat player; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 700; graphics.PreferredBackBufferHeight = 500; } /// <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> public void Start() { if (player == null) { player = new Quadrat(this, ref Quadrat); Components.Add(player); } player.PutinStartPosition(); } protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); BackroundGraphic = Content.Load<Texture2D>("Winter"); Quadrat = Content.Load<Texture2D>("Quadrat"); Services.AddService(typeof(SpriteBatch), spriteBatch); // TODO: use this.Content to load your game content here } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { BackroundGraphic.Dispose(); Quadrat.Dispose(); } /// <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) { KeyboardState keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.Escape)) { this.Exit(); } if(player == null) { Start(); } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); spriteBatch.Draw(BackroundGraphic, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White); spriteBatch.End(); spriteBatch.Begin(SpriteBlendMode.AlphaBlend); base.Draw(gameTime); spriteBatch.End(); } } }
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace Übung2 { /// <summary> /// This is a game component that implements IUpdateable. /// </summary> public class Quadrat : DrawableGameComponent { public Rectangle spriteRectangle; public Vector2 position; public Rectangle screenBounds; public Texture2D texture; public const int WIDTH = 70; public const int HEIGHT = 70; public Quadrat(Game game, ref Texture2D theTexture) : base(game) { texture = theTexture; position = new Vector2(); screenBounds = new Rectangle(0, 0, game.Window.ClientBounds.Width, game.Window.ClientBounds.Height); spriteRectangle = new Rectangle(0, 0, WIDTH, HEIGHT); } public void PutinStartPosition() { position.X = screenBounds.Width / 2; position.Y = screenBounds.Y - HEIGHT; } public override void Update(GameTime gameTime) { KeyboardState keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.Right)) { position.X += 3; } if (keyboard.IsKeyDown(Keys.Left)) { position.X -= 3; } if (keyboard.IsKeyDown(Keys.Up)) { position.Y -= 3; } if (keyboard.IsKeyDown(Keys.Down)) { position.X += 3; } if (position.X < 0) { position.X = 0; } if (position.X > (screenBounds.X - WIDTH)) { position.X = (screenBounds.X - WIDTH); } if (position.Y < 0) { position.Y = 0; } if (position.Y > (screenBounds.Y - HEIGHT)) { position.Y = (screenBounds.Y - HEIGHT); } base.Update(gameTime); } public override void Draw(GameTime gameTime) { SpriteBatch sBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch)); sBatch.Draw(texture, position, spriteRectangle, Color.White); base.Draw(gameTime); } } }
hoffe dass ich hier net im falschen forum bin und ihr mir helfen könnt
ich hab als texur einfach mal das windows bild winter genommen, geht ja nur darum die textur zu laden...
-
Ist ja schön und gut, würde Dir auch gerne Helfen, bin aber leider kein Wahrsager!
Welches Buch ?
Welcher Fehler bzw Fehlermeldung ?
Was geht nicht ?Nix für ungut aber mit deinen Angaben wird Dir leider nimand im Forum helfen können!
mfg
-
Buch: Beginning XNA 3.0 Game Programming From Novice to Professional
es sollte eun rotes quadrat auf der textur winter sein, dass sich steuern
allerdings erscheint es nicht und es gibt eben keine fehlermeldung
das einzige was zu sehen ist ist der client mit der geladenen textur
-
Ok damit kann man ja schon mal was anfangen. Kenne leider das Buch nicht.
Aber hast Du schon mal Probiert das Quadrat ohne der Hintergrundtextur zu zeichen.
Vermute mahl das die Hintergrundtextur das Quadrat überblendet, is aber nur eine Vermutung, abhilfe könnte ein Update auf das gezeichnete Quadrat sein bzw ein this.Update();mfg
-
so jez hab ich die ganze hintergrund textur rausgelöscht... doch sie wurde noch immer angezeigt... da hab ich den pc neu hochgefahren und jetzt sind aber noch immer keine quadrate angezeigt sondern nur auf dem ganzen client verteilt einzelne pixel mit unterschiedlichen farben...
-
falls das buch das ich habe nicht so gut ist... könntet ihr vielleicht eines über XNS programming empfehlen? sry wegen double post
-
Hast Du eigentlich schon Programmier-Erfahrung?
-
Diese zufälligen Pixel, etc. weisen darauf hin, dass dein Zeichnen nicht klappt. Angezeigt werden zufällige Daten die da noch im Grafikspeicher stehen.
Versuch den Bildschirm stattdessen einmal mit einer Clear-Funktion oder Ähnlichem in einer bestimmten Farbe zu überschreiben.
MfG SideWinder