【问题标题】:y position animate in if statementif 语句中的 y 位置动画
【发布时间】:2013-06-07 13:43:16
【问题描述】:

所以我正在制作一个小型 html5 游戏。而且我不知道如何表述。

我有这个:

if (40 in keysDown) { // Player holding down
    hero.y = 300;
}

所以如果玩家按住箭头键,英雄会跳到 300px。但我希望它动画到 300px,我该怎么做?

我试过了:

if (40 in keysDown) { // Player holding down
        hero.animate({"top", "300px"}); 
}

但这不起作用。我认为这是可能的,我只是不知道如何制定这个。

【问题讨论】:

  • 你试过什么?您在标签中提到了jquery-animate。您是否已经尝试使用它?如果是,什么不起作用?
  • 我们不知道您的 hero 对象是什么或做什么......

标签: html if-statement jquery-animate


【解决方案1】:

这是因为您将 y 位置设置为 300,请改用以下代码

hero.y += 300;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多