如果这太愚蠢了,我很抱歉,但对于 C#,尤其是 XNA Framework,我完全是个新手。我从上面收到错误消息;到底为什么它对 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.
}
}
}
请您参考如下方法:
我认为您可能希望将 contentmanager 的实例(this.Content 来自您的 Game 类)传递给您的加载内容函数。
protected override void LoadContent(ContentManager contentManager)
{
//spriteBatch = new SpriteBatch(GraphicsDevice);
CSprite = contentManager.Load<Texture2D>("10by10tile");
}
编辑:不是为了欺骗你或其他什么 - 但 this is a simple - but useful tutorial to push you in the right direction with XNA ,它应该能够向您展示您需要的所有基础知识。
