这是我的代码:
var spriteSheet = new createjs.SpriteSheet({
images: ["images/mario2.png"],
frames: {width:24, height:33, regX: 0, regY: 0},
animations: {
walk_right: [5, 9],
walk_up: [10, 14],
walk_down: [15, 19],
walk_left: [0, 4]
}
});
Player = new createjs.BitmapAnimation(spriteSheet);
Player.name = "Mario";
Player.gotoAndStop("walk_right");
Player.speed = 6;
Player.x = 30;
Player.y = 330;
//Player object toevoegen aan de stage
stage.addChild(Player);
var monsterspritesheet = new createjs.SpriteSheet({
images: ["images/MonsterA.png"], //image to use
frames: {width: 64, height: 54, regX: 0, regY: 0},
animations: {
walk: [0, 9, "walk", 4],
idle: [10, 20, "idle", 4]
}
});
Monster1 = new createjs.BitmapAnimation(monsterspritesheet);
Monster1.name = "Monster";
Monster1.gotoAndStop("walk");
Monster1.speed = 6;
Monster1.x = 180;
Monster1.y = 330;
stage.addChild(Monster1);
stage.update();
对于 hitTest 我使用以下代码:
var testpos = Player.globalToLocal(Monster1.x ,Monster1.y);
if (Player.hitTest(testpos.x, testpos.y) === true)
{
console.log("HIT");
}
问题:当我的玩家在我的怪物下方时,我会收到“HIT”消息,但我想让它在我的玩家击中怪物而不是在它下方时工作。我一直在玩 Player 和 Monster 的 regX 和 regY,但它似乎不起作用。有人知道解决方案吗?