开发者

Troubleshooting Raphael translation animation

开发者 https://www.devze.com 2022-12-08 23:23 出处:网络
I\'m attempting to use Raphael to make a small game, and just want a bit of advice on some code I\'m working on.

I'm attempting to use Raphael to make a small game, and just want a bit of advice on some code I'm working on.

Here's what I have so far, its just a simple example of moving a circle around the screen:

<script type="text/javascript" charset="utf-8">
window.onload = function () {
  var paper = Raphael(10, 50, 320, 200);
  var paper = Raphael(document.getElementById("holder"), 320, 200);
  var paper = Raphael("holder", 320, 200);

  var startx = 30;
  var starty = 3开发者_运维问答0;
  var ANIM_STEP = 5;

  var d = paper.circle(startx,starty,20);
  d.attr("fill", "blue");
  document.onkeyup = function (e) {
    var keyid = e.keyCode;

    switch (keyid)
    {
      // right arrow key
      case 39:
        startx += ANIM_STEP;
        d.cx = d.cx || startx ;
        d.animate({cx: d.cx}, startx);
      break;
    }
  }
};
</script>

Now, the current issue that I'm having is that it only animates the first time the right arrow key was clicked. I verified that 'startx' is incremented with some trace debugging.

I started from the Raphael circle example and mashed in a bit from the ichart, so my way might not be the best...I look forward to your suggestions :)


D'oh

have to set d.cx = startx .... helps to update your variables!

0

精彩评论

暂无评论...
验证码 换一张
取 消