简体   繁体   English

方法没有重载,接受0个参数

[英]No overload for Method takes 0 arguments

I'm currently working on a game in XNA for my school project. 我目前正在为学校项目开发XNA游戏。 Its including paddle and a ball and the idea is to force the ball to leave top border and then you proceed to next harder level and you go until you die. 它包括桨和一个球,其想法是迫使球离开顶部边界,然后您进入下一个更困难的水平,直到死亡。 So this is how my victory-detecting piece of code looks like: 因此,这就是我检测胜利的代码的样子:

if (position.Y < 0 && pbcollide == true)
{
     MessageBox(new IntPtr(0), "Level cleared!", "Nice job", 0);
     paddle.SetInStartPosition();
     paddle.lvcounter++;
}

That piece of code is in my CheckCollisionWall method in my Ball class and pbcollide is bool var I get from Method CheckCollisionPaddle . CheckCollisionWall代码在Ball类的CheckCollisionWall方法中,而pbcollide是从方法CheckCollisionPaddle获取的bool CheckCollisionPaddle I have divided classes for Ball and Paddle , and SetInStartPosition is Paddle class method and lvcounter is Paddle class variable that I use to count levels and increase ball and decrease paddle speed, spawn more powerups etc. 我为BallPaddle划分了类, SetInStartPositionPaddle类的方法, lvcounterPaddle类的变量,我用它来计算级别并增加球和降低桨的速度,产生更多的功率提升等。

The problem occours in my BallUpdate method where I call for CheckCollisionWall Method 问题出现在我的BallUpdate方法中,我在其中调用CheckCollisionWall方法

public void Update()
{
     position += motion * ballSpeed;
     CheckCollisionWall();
     OffBottom();
}

It says no Overload for that method takes 0 arguments. 它说该方法的重载都不接受0个参数。 Which arguments should I put there? 我应该把哪些论点放在那儿? I really don't know what to do. 我真的不知道该怎么办。 I also tried to put my win condition in totaly new method to avoid this but when I do that game starts without errors but absolutely nothing happens when conditions are fulfilled. 我还尝试将获胜条件置于全新的方法中以避免发生这种情况,但是当我这样做时,游戏开始时没有错误,但条件满足时绝对没有任何反应。 So I'm totally confused. 所以我完全糊涂了。

How to solve 怎么解决

No overload for Method takes X arguments 方法不带X参数的重载

  1. Find out which call causes this compiler error. 找出哪个调用导致此编译器错误。 (In your case it is the call CheckCollisionWall(); (您的情况是调用CheckCollisionWall();
  2. Have a close look at the number and types of arguments in this call. 请仔细查看此调用中参数的数量和类型。 (In your case it is zero arguments) (在您的情况下,该参数为零)
  3. Find all definitions of this method. 查找此方法的所有定义。 (You may use Find or Find Usages or intellisense in Visual studio) (您可以在Visual Studio中使用“ Find或“ Find Usages或“智能”)
  4. Compare all definitions/overloads with your call. 将所有定义/过载与您的呼叫进行比较。

The error is caused, when you use a call with a different number of arguments or when at least one argument has a different type when compared to the available definitions/overloads. 当您使用带有不同数量参数的调用时,或者与可用定义/重载相比,至少一个参数具有不同类型时,会导致错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM