Sign in to follow this  
raidzero

Nothing appears on screen when running

Recommended Posts

raidzero    112
I go to debug my program but nothing appears on my screen. I open task manager and I can see the process though.

Main.cs
[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;
using TestGame.Controls;
using TestGame.GameStates;
namespace TestGame
{
public class Main : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
InputHandler inputHandler;
public SpriteBatch spriteBatch;
SpriteFont spriteFont;
MainMenu mainMenu;
Vector2 position;
Texture2D backgroundImage;
public Main()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
inputHandler = new InputHandler();
mainMenu = new MainMenu();
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
}

protected override void Initialize()
{
this.IsMouseVisible = true;

base.Initialize();
mainMenu.MenuInitialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
spriteFont = Content.Load<SpriteFont>(@"Fonts\MainFont");
backgroundImage = Content.Load<Texture2D>(@"Backgrounds\titlescreen");
mainMenu.MenuLoadContent();
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
inputHandler.Update();
if (inputHandler.currentKeyState.IsKeyDown(Keys.Escape))
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(backgroundImage, new Vector2(0, 0), Color.White);
mainMenu.MenuDraw();
spriteBatch.End();
base.Draw(gameTime);
}
}
}
[/CODE]

MainMenu.cs
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace TestGame.GameStates
{
public class MainMenu : Main
{
enum buttonState { hover, up, released, down }
const int numberOfButtons = 4, newGameButtonIndex = 0, loadGameButtonIndex = 1, optionsButtonIndex = 2, quitButtonIndex = 3, buttonHeight = 48, buttonWidth = 80;
Color backgroundButtonColor;
Color[] buttonColor = new Color[numberOfButtons];
Rectangle[] buttonRect = new Rectangle[numberOfButtons];
buttonState[] buttonSt = new buttonState[numberOfButtons];
Texture2D[] buttonTexture = new Texture2D[numberOfButtons];
double[] buttonTimer = new double[numberOfButtons];
bool mousePressed, previouslyPressed = false;
int mouseX, mouseY;
double frameTime;
int buttonPadding;
public void MenuInitialize()
{
for (int i = 0; i < numberOfButtons; i++)
{
buttonSt[i] = buttonState.up;
buttonColor[i] = Color.White;
buttonTimer[i] = 0.0;
buttonRect[i] = new Rectangle(0, buttonPadding, buttonWidth, buttonHeight);
buttonPadding += buttonHeight;
}
}
public void MenuLoadContent()
{
buttonTexture[newGameButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop");
buttonTexture[loadGameButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop");
buttonTexture[optionsButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop");
buttonTexture[quitButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop");
}
public void MenuDraw()
{
for (int i = 0; i < numberOfButtons; i++)
{
spriteBatch.Draw(buttonTexture[i], buttonRect[i], buttonColor[i]);
}
}
}
}
[/CODE]

Share this post


Link to post
Share on other sites
raidzero    112
I managed to get it to run, but I don't understand why it worked.

Main.cs
[CODE]
public class Main : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
InputHandler inputHandler;
public SpriteBatch spriteBatch;
SpriteFont spriteFont;
MainMenu mainMenu;
Vector2 position;
Texture2D backgroundImage;
public Main()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
inputHandler = new InputHandler();
[b]mainMenu = new MainMenu(this);[/b]
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
}
[/CODE]

MainMenu.cs
[CODE]
public class MainMenu
{
Main main;
public MainMenu([b]Game game[/b])
{
[b]main = (Main)game;[/b]
}
[/CODE]

The bold is what I changed. Could anyone explained to me what I did?

Share this post


Link to post
Share on other sites
gladysbuss    100
I have the same problem, and I tried your suggested change too but it did not fix my problem at all! I am feeling stuck! Any other tips please? [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]





[url="http://implrs.com"]T[/url][url="http://financeplr.com"]h[/url][url="http://datingplr.com"]i[/url][url="http://seasonalplr.com"]s[/url] [url="http://arindamchakraborty.com"]i[/url][url="http://datingproductreviews.com"]s[/url] [url="http://valentineproductreviews.com"]a[/url][url="http://fatgoneproductreviews.com"]n[/url] [url="http://movingreel.com"]e[/url][url="http://fitproductreviews.com"]x[/url][url="http://hostinganddomainreviews.com"]c[/url][url="http://imstuffreviews.com"]e[/url][url="http://seasonalstuffreviews.com"]l[/url][url="http://softwareandscriptreviews.com"]l[/url][url="http://techgoreviews.com"]e[/url][url="http://onestepreviews.com/"]n[/url][url="http://www.mosttalkednews.com/"]t[/url] [url="http://halloweenproductreviews.com/"]s[/url][url="http://xmasproductreviews.com/"]i[/url][url="http://fatlossplr.com/"]t[/url][url="http://nuttiecontent.com/make-money"]e[/url] [url="http://nuttiepartners.com/join.html"]I[/url] [url="http://nuttiegraphics.com/conduite-template1/"]love[/url] [url="http://detnoxregistrycleaner.com"]i[/url][url="http://totalinfotips.com"]t[/url]

Share this post


Link to post
Share on other sites
raidzero    112
[quote name='Mary Thurman' timestamp='1329638132' post='4914457']
I have the same problem, and I tried your suggested change too but it did not fix my problem at all! I am feeling stuck! Any other tips please? [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
[/quote]

I think the reason for my problem is that I was creating a new instance of each object in the constructors. So when Main read mainMenu = new MainMenu(); it would then read MainMenu's constructor which was main = new Main(); which would then go back and read mainMenu = new MainMenu(); creating a loop.

Share this post


Link to post
Share on other sites

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