c# - Visual Studio 说 "Method must have a return type"

标签 c# methods spritebatch

它说

"Method must have a return type"

每当我尝试调试它时。

我不知道如何修复这个类

这是一个用 c# 编码的 2d 游戏的播放器类

public class player
{
    public float moveSpeed;
    public Vector2 position;
    public Texture2D texture;

    //default constructer
    public Player(Texture2D tex, Vector2 startPos)
    {
        position  = startPos;
        texture   = tex;
        moveSpeed = 5.0f;
    }
    public void Update(GameTime gameTime)
    {
        //------------------------------------------
        //check for keyboard input(keyboard IF statements)

    }
    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(texture, position, Color.White);
    }
}

最佳答案

您的类是 player 但构造函数是 Player,因为它们不同,所以期望 Player 是方法而不是构造函数

把类名改成Player就可以了

关于c# - Visual Studio 说 "Method must have a return type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22739932/

相关文章:

java - 调用方法和填充随机数组时出现问题

c# - Sprite 批处理: "Begin cannot be called again until End has been successfully called."

c# - 循环滚动纹理

c# - 具有 [Serializable] 属性的类

c# - : Must contain a numeric, 的正则表达式不包括 "SomeText1"

c# - 如何在 C# 中生成 HMAC-SHA1?

java - 渲染图 block map 时 SpriteBatch 性能不佳 [LibGDX]

c# - 将字符串从 C++/CLI 类库传递到 C#

c# - 从库中覆盖方法

java - 将方法提交到 ExecutorService Java