现在的位置: 首页 > 综合 > 正文

《making things move 》第七章

2013年12月12日 ⁄ 综合 ⁄ 共 1299字 ⁄ 字号 评论关闭
《making things move 》第七章

 
疯了~~~这章讲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]

 

抱歉!评论已关闭.