我是 JavaScript 新手。我编写了以下代码:
function Vec2(x_,y_)
{
this.x = x_;
this.y = y_;
}
稍后在文件中我创建了一个这样的函数:
// Init game field array
var initGameField = function () {
var screenCenter = vec2(canvas.width / 2, canvas.height / 2);
var index = 0;
// Init gamefieldArray
for(var y = 0; y < maxVerticalBubbles; y++)
{
if(y%2)
{
for(var x = 0; x < maxHorizontalBubbles - 1; x++)
{
var initPoint = vec2(cellSize / 2 + (screenCenter.x - ((maxVerticalBubbles - 1) * cellSize / 2)) + (x * cellSize),
canvas.height / 2 + (cellSize / 2) + y * cellSize / 1.1);
gameFieldArray[index] = initPoint;
}
}
else
{
for(var x = 0; x < maxHorizontalBubbles; x++)
{
var initPoint = vec2(cellSize / 2 + (screenCenter.x - (maxVerticalBubbles * cellSize / 2)) + (x * cellSize),
canvas.height / 2 + (cellSize / 2) + y * cellSize / 1.1);
gameFieldArray[index] = initPoint;
}
}
}
}
但是当我尝试在 javascript -file 的末尾运行 initGameField 函数时,我在“initGameField”内的“vec2 not defined”上出现错误......应该如何以正确的方式完成?为什么在 initGameField -function 之前和运行 initGameField -function 之前引入了函数 vec2?