[笔记] 《making things move 》第七章

[ 2006-11-03 14:08:03 | 发布: N神 ]
字体大小: | |
疯了~~~这章讲onRelease ,onPress ,startDrag .....
只有一个有点价值的代码~~还好这是基础运动的最后一章了~

唯一有价值的:throw~~


init();
function init()
{
  dragging = false;
  friction = 0.98;
  bounce = -0.7;
  gravity = 0.5;
  top = 0;
  left = 0;
  bottom = Stage.height;
  right = Stage.width;
  ball = attachMovie("ball", "ball", 0);
  ball._x = Stage.width / 2;
  ball._y = Stage.height / 2;
  vx = Math.random() * 10 - 5;
  vy = Math.random() * 10 - 5;
}
ball.onPress = function()
{
  oldX = ball._x;
  oldY = ball._y;
  dragging = true;
  ball.startDrag();
};
ball.onRelease = function()
{
  dragging = false;
  ball.stopDrag();
};
ball.onReleaseOutside = function()
{
  dragging = false;
  ball.stopDrag();
};
function onEnterFrame(Void):Void
{
  if (!dragging)
  {
    vy += gravity;
    vx *= friction;
    vy *= friction;
    ball._x += vx;
    ball._y += vy;
    if (ball._x + ball._width / 2 > right)
    {
      ball._x = right - ball._width / 2;
      vx *= bounce;
    }
    else if (ball._x - ball._width / 2 < left)
    {
      ball._x = left + ball._width / 2;
      vx *= bounce;
    }
    if (ball._y + ball._height / 2 > bottom)
    {
      ball._y = bottom - ball._height / 2;
      vy *= bounce;
    }
    else if (ball._y - ball._height / 2 < top)
    {
      ball._y = top + ball._height / 2;
      vy *= bounce;
    }
  }
  else
  {
    vx = ball._x - oldX;
    vy = ball._y - oldY;
    oldX = ball._x;
    oldY = ball._y;
  }
}
[最后编辑于 N神, at 2006-11-03 14:12:38]



浏览模式: 阅读全文 | 评论: 1 | 引用: 0 | Toggle Order | 阅读: 4804
1
引用 lovejulia*
[ 2006-11-04 01:50:21 ]
啊,这个效果真不错啊。
1

发表评论
表情
[arrow] [biggrin] [confused] [cool]
[cry] [eek] [evil] [exclaim]
[frown] [idea] [lol] [mad]
[mrgreen] [neutral] [question] [razz]
[redface] [rolleyes] [sad] [smile]
[surprised] [twisted] [wink] [sweat]
打开 UBB 编码
自动识别链接
显示表情
隐藏的评论
用户名:   密码:   注册?
验证码 * 请输入验证码