对,我正在使用canvas和javascript创建sidescrolling无尽的空间主题游戏。我只是使用向上和向下的箭头控制飞船,并且我想实施某种运动缓解,这样当我放开钥匙时船不会停下来。我环顾四周,并没有发现任何东西加上我自己的尝试只是不工作,这是我已经试过......使用键盘控制的帆布游戏中的滑动角色运动
Jet.prototype.checkDirection = function() {
if (this.isUpKey) {
this.drawY -= this.speed;
if (this.speed < 5) {
this.speed += 0.1;
}
}
if (this.isDownKey) {
this.drawY += this.speed;
if (this.speed < 5) {
this.speed += 0.1;
}
}
if (!this.isUpKey) {
if (!this.isDownKey) {
if (this.speed >= 0) {
this.drawY -= this.speed;
this.speed -= 1;
}
}
}
if (!this.isDownKey) {
if (!this.isUpKey) {
if (this.speed >= 0) {
this.drawY += this.speed;
this.speed -= 1;
}
}
}
研究力,动量和摩擦力的基本物理模拟。做到这一点,以便你的钥匙给船上添加一种力量,这种力量有一个质量,并在其上施加摩擦力......通过适当选择参数(质量,摩擦,力),你可以创建各种行为。这是棘手的,但!但您可以稍后使用它:获得船舶更快动作的奖励或负面奖励,使船舶变得沉重。 – ppeterka 2013-03-11 16:54:37
几乎只是用JavaScript创建物理定律O.O – VoidKing 2013-03-11 16:55:52