首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >此方法不接受此参数的空值。

此方法不接受此参数的空值。
EN

Stack Overflow用户
提问于 2013-08-29 03:38:23
回答 2查看 311关注 0票数 0

我想为windows phone 7制作一个宠物护理游戏,但我有问题,它告诉我我有一个空方法,但我不知道为什么我在游戏中每个州都有一个枚举。

下面是消息的图片:new=10%253A1377747418

这是主文件。

代码语言:javascript
复制
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.Input.Touch;
using Microsoft.Xna.Framework.Media;
using Mochi_Mochi_Pets_Life.Script.Screen;

namespace Mochi_Mochi_Pets_Life
{

public class MainFile : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    ScreenStates screentState;

    Rectangle TouchS_Y_X;

    Logo logo;
    Menu0 menu;
    Choose_Pets choose_pets;
    ScreenStates.CurrentGameState GameState;

    public MainFile()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        Content.RootDirectory = "Script\\Screen";

        choose_pets = new Choose_Pets();

        this.screentState = new ScreenStates();
        this.logo = new Logo(GraphicsDevice);
        this.menu = new Menu0();
        // Frame rate is 30 fps by default for Windows Phone.
        TargetElapsedTime = TimeSpan.FromTicks(333333);

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

        GameState = ScreenStates.CurrentGameState.Logo;


    }


    protected override void Initialize()
    {
        choose_pets.Initialize_choosepets();
        // TODO: Add your initialization logic here
        base.Initialize();
    }


    protected override void LoadContent()
    {
        TouchS_Y_X = new Rectangle(0, 0, 1, 1);
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        if (GameState == ScreenStates.CurrentGameState.Logo)
            this.logo.Load(this.Content, this.GraphicsDevice);

        if (GameState == ScreenStates.CurrentGameState.Menu)
            this.menu.Load_Menu(GraphicsDevice, Content);

        if (logo.FadeOut_logo == true)
            GameState = ScreenStates.CurrentGameState.Menu;

        if (GameState == ScreenStates.CurrentGameState.CharactersChooser)
        this.choose_pets.Load_ChoosePet(this.Content, this.GraphicsDevice);
        // TODO: use this.Content to load your game content here
    }


    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
        //this.logo.Unload_logo(Content);
    }


    protected override void Update(GameTime gameTime)
    {

        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

                    if (GameState == ScreenStates.CurrentGameState.Logo)
                logo.Update_logo(gameTime);


                    if (GameState == ScreenStates.CurrentGameState.CharactersChooser)
                    choose_pets.Update_petchoose(gameTime);

        // TODO: Add your update logic here

        base.Update(gameTime);
    }


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

        spriteBatch.Begin();

                    if (GameState == ScreenStates.CurrentGameState.Logo)
                        logo.Draw(spriteBatch);

                    if (logo.FadeOut_logo == true)
                        menu.Draw_Menu(spriteBatch);

                    if (GameState == ScreenStates.CurrentGameState.CharactersChooser)
                        choose_pets.Draw_petChoose(spriteBatch);

        spriteBatch.End();
        base.Draw(gameTime);
    }
}
}

这个菜单给我带来了问题

代码语言:javascript
复制
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Content;

    namespace Mochi_Mochi_Pets_Life
    {
class Menu0
{
    Texture2D Text2D_Background;
    Rectangle Rec_Background;

    Texture2D ButtonText2DPlay;
    Rectangle ButtonRecPlay;


    public void Load_Menu(GraphicsDevice Graphics_Menu, ContentManager Content_Menu)
    {
        Content_Menu.RootDirectory = "Content"; 

        Text2D_Background = Content_Menu.Load<Texture2D>("UI\\MenuBack");
        Rec_Background = new Rectangle(0, 0, Graphics_Menu.Viewport.Width,                 Graphics_Menu.Viewport.Height);

        ButtonText2DPlay = Content_Menu.Load<Texture2D>("UI\\Buttons\\New Games");
        ButtonRecPlay = new Rectangle(Graphics_Menu.Viewport.Width, 400, 150, 40);
    }


    public void Draw_Menu(SpriteBatch Spritebatch_Menu)
    {
        Spritebatch_Menu.Draw(Text2D_Background, Rec_Background, Color.White);
        Spritebatch_Menu.Draw(ButtonText2DPlay, ButtonRecPlay, Color.White);
    }
}
    }

好的,这是做的是,当我的标志褪色为==真,游戏状态跳转到主马努,但它永远不会发生错误,我会感谢你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-29 11:29:00

Loading_Menu从不被调用,因此纹理Text2D_Background总是为空。

您应该认识到,LoadContent只在游戏中被调用,所以比较游戏状态是无用的,因为只会加载Logo内容。

作为解决方案,您可以在initalization时加载所有内容,如果需要的内容之前没有加载,则可以在游戏状态更改时加载它。

票数 1
EN

Stack Overflow用户

发布于 2013-08-29 11:36:13

我认为您的Text2D_Background是空的,这是因为您从不调用Load_Menu。您在gameState中签入LoadContent,它将返回false

代码语言:javascript
复制
if (GameState == ScreenStates.CurrentGameState.Menu)

LoadContent只被调用一次,我不明白为什么要检查gameState值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18501894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档