Jump to content
  • Advertisement
Sign in to follow this  
vaironl

XNA bitmap won't fit to screen

This topic is 2532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys I'm sorry to bother you with this chuck of coding but I just can't see what's causing the problem. The problem is that I have a 500x500 screen I made while practicing the tutorial in Riemers XNA tutorial 2D.

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;

namespace XNAtutorial
{

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
GraphicsDevice device;
Texture2D backgroundTexture;
Texture2D foregroundTexture;


int screenWidth;
int screenHeight;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

protected override void Initialize()
{


base.Initialize();
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Riemer's 2D XNA Tutorial";

}


protected override void LoadContent()
{

spriteBatch = new SpriteBatch(GraphicsDevice);
device = graphics.GraphicsDevice;

foregroundTexture = Content.Load<Texture2D>("foreground");
backgroundTexture = Content.Load<Texture2D>("background");
screenWidth = device.PresentationParameters.BackBufferWidth;
screenHeight = device.PresentationParameters.BackBufferHeight;


}


protected override void UnloadContent()
{
}


protected override void Update(GameTime gameTime)
{

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


base.Update(gameTime);
}


protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
DrawScenery();
spriteBatch.End();


base.Draw(gameTime);





}


private void DrawScenery()
{
Rectangle screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
spriteBatch.Draw (backgroundTexture, screenRectangle, Color.White );
spriteBatch.Draw(foregroundTexture, screenRectangle, Color.White);


}


}
}

Share this post


Link to post
Share on other sites
Advertisement
I Found the problem but can someone explain it to me.... here it is
the base.Initialize(); , was suppose to go at the end of the protected override part , which I don't know if its a class or what.

protected override void Initialize()
{

graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Riemer's 2D XNA Tutorial";

base.Initialize();
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!