Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

help making a main menu

$
0
0
hi all :)

i need some help i just can't get my code to work. i want to make a main menu using bool to switch from one screen to the other :) here is my 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 test_stat2
{
    
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        bool menu;
        bool play;

        SpriteFont Font;

        KeyboardState currentKey;

        Texture2D playtext;
        Texture2D menutext;

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

            graphics.PreferredBackBufferWidth = 1080;
            graphics.PreferredBackBufferHeight = 720;
            graphics.ApplyChanges();
        }

       
        protected override void Initialize()
        {
            

            base.Initialize();
        }

      
        protected override void LoadContent()
        {
           
            spriteBatch = new SpriteBatch(GraphicsDevice);

            playtext = Content.Load<Texture2D>("play");
            menutext = Content.Load<Texture2D>("menu");

            Font = Content.Load<SpriteFont>("font");

            menu = true;
            play = false;
         
        }

        
        protected override void UnloadContent()
        {
            
        }

        
        protected override void Update(GameTime gameTime)
        {

            if (Keyboard.GetState().IsKeyDown(Keys.Escape)) 
                this.Exit();

            currentKey = new KeyboardState();

            if (menu)
            { 
                if (currentKey.IsKeyDown(Keys.A))
                {
                    menu = false;
                    play = true;
                    return;
                }
            
            }
            else if (play)
            { 
                if(currentKey.IsKeyDown(Keys.S))
                {
                    play = false;
                    menu = true;
                    return;
                }
            
            }
         


            base.Update(gameTime);
        }

    
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            if(menu)
            {
                spriteBatch.Draw(menutext, new Rectangle(0, 0, 1080, 720), Color.White);
            }

           else if (play)
            {
                spriteBatch.Draw(playtext, new Rectangle(0, 0, 1080, 720), Color.White);
            }

            spriteBatch.DrawString(Font, " play " + play.ToString() + " menu " + menu.ToString(), new Vector2(30, 400), Color.Red);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>