XNA 框架:ContentManager.Content.Load(“10by10tile”) 是一种“方法”;但用作“类型”;

发布于 2024-09-27 08:35:48 字数 1136 浏览 4 评论 0原文

如果这太愚蠢了,我很抱歉,但对于 C#,尤其是 XNA 框架,我完全是新手。我收到上面的错误消息;到底为什么它适用于 Platformer1 的玩家代码但不适用于我?!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace WindowsGame1
{
    class Cell
    {
            public bool alive;
            public Texture2D CSprite;
            public int x
            {
                get { return x; }
                set { x = value; }
            }
            public int y
            {
                get { return y; }
                set { y = value; }
            }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {

        }

        public void Update(GameTime gameTime)
        {

        }

        protected override void LoadContent()
        {
            //spriteBatch = new SpriteBatch(GraphicsDevice);
            CSprite = new ContentManager.Load<Texture2D>("10by10tile"); // TODO: This does NOT work for some reason.
        }
    }
}

I'm sorry if this is insanely stupid, but I'm a total newbie when it comes to C# and especially the XNA Framework. I got the error message from above; why in the heck does it work for Platformer1's Player code but not for me?!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace WindowsGame1
{
    class Cell
    {
            public bool alive;
            public Texture2D CSprite;
            public int x
            {
                get { return x; }
                set { x = value; }
            }
            public int y
            {
                get { return y; }
                set { y = value; }
            }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {

        }

        public void Update(GameTime gameTime)
        {

        }

        protected override void LoadContent()
        {
            //spriteBatch = new SpriteBatch(GraphicsDevice);
            CSprite = new ContentManager.Load<Texture2D>("10by10tile"); // TODO: This does NOT work for some reason.
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

并安 2024-10-04 08:35:48

我认为您可能希望将 contentmanager 的实例(来自您的 Game 类的 this.Content)传递给您的加载内容函数。

protected override void LoadContent(ContentManager contentManager)
        {
            //spriteBatch = new SpriteBatch(GraphicsDevice);
            CSprite = contentManager.Load<Texture2D>("10by10tile");
        }

编辑:不是为了欺骗你或任何东西 - 但这是一个简单但有用的教程,可以推动你走向正确的方向XNA 的指导,它应该能够向您展示您需要的所有基础知识。

I'm thinking that you may want to pass the instance of contentmanager - (this.Content from your Game class) - to your load content function.

protected override void LoadContent(ContentManager contentManager)
        {
            //spriteBatch = new SpriteBatch(GraphicsDevice);
            CSprite = contentManager.Load<Texture2D>("10by10tile");
        }

Edit: Not to palm you off or anything - but this is a simple - but useful tutorial to push you in the right direction with XNA, which should be able to show you all the basics you need.

我也只是我 2024-10-04 08:35:48

ContentManager.Load 是一种方法。您不需要“新”声明。尝试:

protected override void LoadContent()
{
       CSprite = ContentManager.Load<Texture2D>("10by10tile");
}

ContentManager.Load is a method. You don't need the "new" statement. Try:

protected override void LoadContent()
{
       CSprite = ContentManager.Load<Texture2D>("10by10tile");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文