Sign in to follow this  

XNA bitmap won't fit to screen

This topic is 2378 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 [url="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Drawing_fullscreen_images.php"]Riemers XNA tutorial 2D[/url].

[code]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);


}


}
}
[/code]

Share this post


Link to post
Share on other sites
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.

[code] protected override void Initialize()
{

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

base.Initialize();
}
[/code]

Share this post


Link to post
Share on other sites
You might read [url="http://www.c-sharpcorner.com/UploadFile/ecabral/OOPSandDotNET106252005024236AM/OOPSandDotNET1.aspx"]this series[/url] on OOP.

Share this post


Link to post
Share on other sites

This topic is 2378 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this