错误1136:参数的数量不正确。预期0
问题描述:
有人可以告诉我这段代码有什么问题...如何解决这个代码我使用这段代码让怪物移动到检查点......但是所有的检查点从22-30行得到一些警告1136 :不正确的参数数目。预计0错误1136:参数的数量不正确。预期0
package Game
{
import flash.display.MovieClip;
import flash.events.*;
import flash.geom.*;
public class Monster extends MovieClip
{
public var currLife:Number;
private var maxLife, gold, speed, currIndex, slowTimer:Number;
private var checkPoints:Array;
public function Monster()
{
maxLife = C.MONSTER_LIFE;
currLife = maxLife;
speed = C.MONSTER_SPEED;
currIndex = 0;
checkPoints = new Array();
checkPoints.push(new Point(85,140));
checkPoints.push(new Point(85,320));
checkPoints.push(new Point(325,320));
checkPoints.push(new Point(325,200));
checkPoints.push(new Point(265,200));
checkPoints.push(new Point(265,80));
checkPoints.push(new Point(505,80));
checkPoints.push(new Point(505,380));
checkPoints.push(new Point(630,380));
}
public function update()
{
var finalSpeed:Number;
if (slowTimer > 0)
{
finalSpeed = speed/2;
slowTimer--;
}
else
finalSpeed = speed;
if (currIndex < checkPoints.length)
{
//move in the direction of the checkpoint
if (this.x < checkPoints[currIndex].x)
this.x += Math.min(finalSpeed, Math.abs(this.x -
checkPoints[currIndex].x));
else if (this.x > checkPoints[currIndex].x)
this.x -= Math.min(finalSpeed, Math.abs(this.x -
checkPoints[currIndex].x));
if (this.y < checkPoints[currIndex].y)
this.y += Math.min(finalSpeed, Math.abs(this.y -
checkPoints[currIndex].y));
else if (this.y > checkPoints[currIndex].y)
this.y -= Math.min(finalSpeed, Math.abs(this.y -
checkPoints[currIndex].y));
if ((this.x == checkPoints[currIndex].x) &&
(this.y == checkPoints[currIndex].y))
{
currIndex += 1;
}
}
//display
if (currLife > 0)
mcLifeBar.width = Math.floor((currLife/maxLife)*
C.LIFEBAR_MAX_WIDTH);
else
mcLifeBar.width = 0;
}
public function takeDamage(amtDamage)
{
if (this.currLife <= 0)
return;
this.currLife -= amtDamage;
if (this.currLife <= 0)
{
this.gotoAndPlay("death");
}
}
public function slowDown(amt)
{
slowTimer = amt;
}
public function hasReachedDestination()
{
return (this.currIndex == checkPoints.length);
}
}
}
请帮我解决这个问题......我只是在AS3一个小白
我使用该代码在上面GameController.as ,这是更新GameController
public function update(evt:Event)
{
//Update the mobs
if ((currWave < maxWave) && (monsters.length == 0))
{
currWave++;
//spawn the monsters
spawnWave(currWave);
}
for (i=monsters.length - 1; i >= 0; i--)
{
if (monsters[i].currLife > 0)
{
monsters[i].update();
}
//Check if monster reaches the end of their path
if (monsters[i].hasReachedDestination())
{
monsters[i].gotoAndStop("remove");
life -= 1;
currGold -= C.MONSTER_GOLD;
}
if (monsters[i].currentLabel == "remove")
{
mcGameStage.removeChild(monsters[i]);
monsters.splice(i,1);
//Award Gold
currGold += C.MONSTER_GOLD;
}
}
//Update all the towers
for (i in towers)
{
towers[i].update();
}
//Update all the bullets
for (i=bullets.length - 1; i >= 0; i--)
{
bullets[i].update();
if (bullets[i].currentLabel == "remove")
{
mcGameStage.removeChild(bullets[i]);
bullets.splice(i,1);
}
}
//******************
//Handle Display
//******************
//Display new Score
mcGameUI.txtLife.text = String(life);
mcGameUI.txtGold.text = String(currGold);
mcGameUI.txtWave.text = String(currWave) + "/" + String(maxWave);
//Check for end game
if (life <= 0)
{
gameOver();
//stop all subsequent code in this update to run
return;
}
else if ((currWave == maxWave) && (monsters.length == 0))
{
gameWin();
}
}
private function spawnMonster(xPos, yPos)
{
var monsterToSpawn = new Monster();
monsterToSpawn.x = xPos;
monsterToSpawn.y = yPos;
monsters.push(monsterToSpawn);
mcGameStage.addChild(monsterToSpawn);
}
private function spawnWave(currWave)
{
if (currWave == 1)
{
spawnMonster(C.MONSTER_START_X, C.MONSTER_START_Y);
}
else if (currWave == 2)
{
for (i = 0; i < 2; i++)
{
spawnMonster(C.MONSTER_START_X - 40*i, C.MONSTER_START_Y);
}
}
}
答
您好我不明白为什么你收到此错误,但是这可以帮助你,
尝试后续代码,而不是点();
var checkPoints:Array=new Array({x:85,y:140},
{x:85,y:320},
{x:325,y:320},
{x:325,y:200},
{x:265,y:200},
{x:265,y:80},
{x:505,y:80},
{x:505,y:380},
{x:630,y:380}
);
+0
谢谢,先生@mdemir它的工作 – 2015-03-13 11:13:25
在哪条线路上出现此错误?尝试调试并找到 – ketan 2015-03-13 09:11:17
从行checkPoints.push(新Point(85,140))开始;直到checkPoints.push(新点(630,380));全部都有错误1136:参数的数量不正确。预计0. @ketan ...你能告诉我这有什么问题? – 2015-03-13 09:15:57
没有。没有什么像错误。 C.MONSTER_LIFE中'c'是什么意思? – ketan 2015-03-13 09:19:19