我正在使用EaselJS在javascript中制作游戏。我遇到了碰撞检测问题。
我将其用于命中检测(因为我检查形状是否受到影响,而不仅仅是点数)https://github.com/olsn/Collision-Detection-for-EaselJS
这看起来效果很好,但由于某种原因,不同形状的坐标似乎总是“关闭”。没有olsns碰撞检测我有完全相同的问题。我认为这是因为它们处于不同的坐标空间,但我不知道如何获得统一的坐标。理想情况下,我希望所有内容都使用相同的坐标系,只有键盘交互,因此鼠标坐标并不重要。
我与localtoglobal,globaltolocal和localtolocal混淆了但似乎根本不需要任何工作。
我觉得我遗漏了一些关于easelJS处理坐标的重要事项。
这里有一些(相关的)代码:
window.stage = new createjs.Stage("CanvasGeo");
function drawShip() {
// Initializes ship graphics
shipG = new createjs.Shape();
shipG.graphics.beginFill("DeepSkyBlue").drawCircle(x, y, circlesize);
stage.addChild(shipG);
}
function drawShape() {
shapeG = new createjs.Shape();
if (type == "Rect") {
shapeG.graphics.beginFill(colour).drawRect(x, y, shapesize, shapesize);
} else if (type == "Triangle") {
shapeG.graphics.beginFill(colour).drawPolyStar(x, y, shapesize, 3, 0.5, getRandomInt(1, 359));
} else if (type == "Star") {
shapeG.graphics.beginFill(colour).drawPolyStar(x, y, shapesize, 5, 0.7, getRandomInt(1, 359));
}
stage.addChild(shapeG);
}
function findSpawnPoint() {
var direction = getRandomInt(1, 5);
switch (direction) {
// TOP
case 1:
console.log("Spawn shape on top");
x = getRandomInt((shapesize * 2), canvasWidth - (shapesize * 2));
y = -1 * shapesize;
xVel = getRandomSpeed();
yVel = Math.abs(getRandomSpeed());
break;
// LEFT
case 2:
console.log("Spawn shape on left");
x = -1 * shapesize;
y = getRandomInt((shapesize * 2), canvasHeight - (shapesize * 2));
xVel = Math.abs(getRandomSpeed());
yVel = getRandomSpeed();
break;
// RIGHT
case 3:
console.log("Spawn shape on right");
x = shapesize + canvasWidth;
y = getRandomInt((shapesize * 2), canvasHeight - (shapesize * 2));
xVel = -1 * Math.abs(getRandomSpeed());
yVel = getRandomSpeed();
break;
// BOTTOM
case 4:
console.log("Spawn shape on bottom");
x = getRandomInt((shapesize * 2), canvasWidth - (shapesize * 2));
y = shapesize + canvasHeight;
xVel = getRandomSpeed();
yVel = -1 * Math.abs(getRandomSpeed());
break;
}
}
this.hitCheck = function(ship) {
if (!null == ndgmr.checkRectCollision(shapeG, ship)) {
this.hitAction();
}
}
感谢您的帮助:)