C# 尝试在XNA程序中执行图像菜单时遇到构造函数错误

C# 尝试在XNA程序中执行图像菜单时遇到构造函数错误,c#,.net,xna,windows-phone-8,xna-4.0,C#,.net,Xna,Windows Phone 8,Xna 4.0,这是ImageMenuGame.cs的代码。尝试在Xna中执行菜单,为游戏开发而练习,它将错误显示为构造函数错误。我是XNA的新手。 还将屏幕截图与代码一起粘贴。提前谢谢 namespace ImageMenu { /// <summary> /// This is the main type for your game /// </summary> /// public class ImageMenuGame : Micros

这是ImageMenuGame.cs的代码。尝试在Xna中执行菜单,为游戏开发而练习,它将错误显示为构造函数错误。我是XNA的新手。 还将屏幕截图与代码一起粘贴。提前谢谢

namespace ImageMenu
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    /// 

    public class ImageMenuGame : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        SpriteFont font;

        Texture2D texImageMenuItem;

        List<ImageMenuItem> Menu;

        int TotalMenuItems = 4;

        int index = 0;

        int currentIndex;


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

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            // Extend battery life under lock.
            InactiveSleepTime = TimeSpan.FromSeconds(1);
        }

        /// <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>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            Menu = new List<ImageMenuItem>();


                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);

            // TODO: use this.Content to load your game content here
            texImageMenuItem = Content.Load<Texture2D>("Imageitem");
            font = Content.Load<SpriteFont>("gameFont");

            int X = 150;
            int Y = 240;

            for (int i = 0; i < TotalMenuItems; i++)
            {

                ImageMenuItem item = new ImageMenuItem(new Vector2(X + i * (texImageMenuItem.Width + 20), Y), texImageMenuItem, spriteBatch);
                item.Index = index++;

                Menu.Add(item);


            }


        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            Vector2 tapPosition = new Vector2();
            TouchCollection touches = TouchPanel.GetState();


            if (touches.Count > 0 && touches[0].State == TouchLocationState.Pressed)
            {

                tapPosition = touches[0].Position;
                foreach(ImageMenuItem item in Menu)
                {
                    item.Update(gameTime, tapPosition);
                    if (item.Tap)
                    {
                        currentIndex = item.Index;

                    }

                }

            }

                      base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            foreach (ImageMenuItem item in Menu)
            {
                item.Draw(gameTime);
            }

            spriteBatch.DrawString(font, "CurrentIndex: " + currentIndex.ToString(), new Vector2(0,0), Color.White);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
名称空间图像菜单
{
/// 
///这是游戏的主要类型
/// 
/// 
公共类ImageMenuGame:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
SpriteFont字体;
纹理2d texImageMenuItem;
列表菜单;
int TotalMenuItems=4;
int指数=0;
int-currentIndex;
公共图像名称()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
//Windows Phone的帧速率默认为30 fps。
targetExpressedTime=时间跨度(333);
//在锁定状态下延长电池寿命。
InactiveSleepTime=时间跨度(从秒开始)(1);
}
/// 
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
/// 
受保护的覆盖无效初始化()
{
//TODO:在此处添加初始化逻辑
菜单=新列表();
base.Initialize();
}
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
texImageMenuItem=Content.Load(“Imageitem”);
font=Content.Load(“gameFont”);
int X=150;
int Y=240;
对于(int i=0;i0&&touchs[0].State==TouchLocationState.Pressed)
{
t位置=接触[0]。位置;
foreach(菜单中的ImageMenuItem项)
{
更新(游戏时间,位置);
如果(项目点击)
{
currentIndex=项目索引;
}
}
}
更新(游戏时间);
}
/// 
///这就是所谓的比赛应该平局的时候。
/// 
///提供计时值的快照。
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
//TODO:在此处添加图形代码
spriteBatch.Begin();
foreach(菜单中的ImageMenuItem项)
{
抽签(游戏时间);
}
spriteBatch.DrawString(字体,“CurrentIndex:+CurrentIndex.ToString(),新矢量2(0,0),Color.White);
spriteBatch.End();
基础。抽签(游戏时间);
}
}
}
//ImageMenuItem.cs

namespace ImageMenu
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class ImageMenuItem : Microsoft.Xna.Framework.GameComponent
    {
        SpriteBatch spriteBatch;

        Texture2D texture;

        public Vector2 Position;

        public Vector2 Origin;

        public bool Tap;

        float timer = 0;

        const float MinScale = 0.8f;

        const float MaxScale = 1;

        float scale = 0.8f;

        public int index = 0;

        public Rectangle Bound
        {
            get
            {
                return new Rectangle(
                    (int) (Position.X - Origin.X * scale),
                    (int) (Position.Y - Origin.Y * scale),
                    (int) (texture.Width * scale),
                    (int) (texture.Height * scale));            
            }
        }

        public ImageMenuItem(Game game, Vector2 Location, Texture2D Texture, SpriteBatch SpriteBatch)
            : base(game)
        {
            // TODO: Construct any child components here

           {
               Position = Location;
               texture = Texture;
               spriteBatch = SpriteBatch;

               Origin = new Vector2 (texture.Width / 2, texture.Height / 2);
           }



        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// 


  //  public override void Update(GameTime gameTime)
    //    {
            // TODO: Add your update code here
       //         base.Update(gameTime);
    //    }



            public void Update(GameTime gameTime, Vector2 tapPosition)
            {
            // if the tapped position within the text menu item bound,
            // set Tap to true and trigger the OnTap event
            Tap = Bound.Contains((int)tapPosition.X,
            (int)tapPosition.Y);
            // Accumulate the game elapsed time
            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                 base.Update(gameTime);
            }
            public void Draw(GameTime gameTime)
            {

                if (Tap)
                {
                    if (scale <= MaxScale && timer > 200)
                    {
                        scale += 0.1f;

                        }
                        spriteBatch.Draw(texture, Position, null, Color.Red, 0f, Origin, scale, SpriteEffects.None, 0f);
                }
                    else
                    {

                        if (scale > MinScale && timer > 200)
                        {
                            scale -= 0.1f;

                        }
                            spriteBatch.Draw(texture, Position, null, Color.White, 0f, Origin, scale, SpriteEffects.None, 0f);


                    }

                }


        }
    }
名称空间图像菜单
{
/// 
///这是一个实现IUpdateable的游戏组件。
/// 
公共类ImageMenuItem:Microsoft.Xna.Framework.GameComponent
{
SpriteBatch SpriteBatch;
纹理2D纹理;
公共向量2位置;
公共向量2起源;
公共水龙头;
浮动计时器=0;
常量浮点最小刻度=0.8f;
常量浮点最大刻度=1;
浮子刻度=0.8f;
公共int指数=0;
公共矩形边界
{
得到
{
返回新矩形(
(int)(位置X-原点X*刻度),
(int)(位置Y-原点Y*刻度),
(int)(纹理宽度*比例),
(int)(纹理高度*比例);
}
}
公共图像菜单项(游戏、矢量2位置、纹理2D纹理、SpriteBatch SpriteBatch)
:基地(游戏)
{
//TODO:在此构造任何子组件
{
位置=位置;
纹理=纹理;
spriteBatch=spriteBatch;
原点=新矢量2(texture.Width/2,texture.Height/2);
}
}
/// 
///允许游戏组件在启动前执行其需要的任何初始化
///运行。在这里,它可以查询任何必需的服务并加载内容。
public class ImageMenuItem {

    public ImageMenuItem(Vector2 vec, Texture2D tex, SpriteBatch sb){
    //assign
    }
}
public ImageMenuItem(Game game, Vector2 Location, Texture2D Texture, SpriteBatch SpriteBatch)
                     ^^^^^^^^
ImageMenuItem item = new ImageMenuItem(this, new Vector2(X + i * (texImageMenuItem.Width + 20), Y), texImageMenuItem, spriteBatch); // this is your Game