所以,我从使用Phaser切换到使用Canvas元素制作游戏。
我显示了地图,并实现了占位符spritesheet,但该移动仅适用于精灵面向的方向。
这是我的代码:
Player.prototype.checkDirection = function () {
var newDrawX = this.drawX,
newDrawY = this.drawY,//draw specific specific points on x and y coordinates
newMoveX = this.moveX,
newMoveY = this.moveY;
obstacleCollision = false;
if (this.isUpKey) {
newDrawY -= this.speed;
this.moveY -= 35;
this.srcX = 48; //Facing North
this.srcY = 72;
} else if (this.isDownKey) {
newDrawY += this.speed;
this.moveY += 35;
this.srcX = 48; //Facing South
this.srcY = 1;
} else if (this.isRightKey) {
newDrawX += this.speed;
this.moveX += 31;
this.srcX = 48; //Facing East
this.srcY = 36;
} else if (this.isLeftKey) {
newDrawX -= this.speed;
this.moveX -= 31;
this.srcX = 48; //Facing West
this.srcY = 108;
}
if (!obstacleCollision && !outOfBounds(this, newDrawX, newDrawY)) {
this.drawX = newDrawX;
this.drawY = newDrawY;
};
有关如何解决此问题的任何想法?
答案 0 :(得分:0)
我发现了我的问题。
删除此内容:
&& !outOfBounds(this, newDrawX, newDrawY)
足以允许角色移动。我解决了自己的问题!