It says
"Method must have a return type"
whenever I try to debug it.
I don't know how to fix this class
This is a player class for a c# coded 2d Game
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);
}
}
Methods use the return operator to return a value. Any method that is not declared void must contain a return statement. The data type of the value returned by the return statement must match the data type that the method claims to return; you can't return an Object from a method declared to return an integer.
Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so.
We use “void” keyword if we want a method not to return anything but perform operations only / Execute group of statements. NOTE: if return type is anything except void, then method must have “return “statement.
Defining Methods in C# The return type is the data type of the value the method returns. If the method is not returning any values, then the return type is void. Method name − Method name is a unique identifier and it is case sensitive. It cannot be same as any other identifier declared in the class.
Your class is player but the constructor is Player, because they are different it is expecting Player to be a method rather than a constructor
Change the class name to Player and you will be good
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With