zoukankan      html  css  js  c++  java
  • actionscript中常用的基本公式(4)

    移除出界对象:

     if(sprite.x - sprite.width / 2 > right ||
      sprite.x + sprite.width / 2 < left || 
      sprite.y – sprite.height / 2 > bottom || 
      sprite.y + sprite.height / 2 < top)
    { 
      // 移除影片的代码 
    }
    

    重置出界对象: 

    if(sprite.x - sprite.width / 2 > right || 
        sprite.x + sprite.width / 2 < left || 
        sprite.y – sprite.height / 2 > bottom || 
        sprite.y + sprite.height / 2 < top) 
    { 
        // 重置影片的位置和速度 
    }
    

    屏幕环绕出界对象:

    if (sprite.x - sprite.width / 2 > right)
    { 
        sprite.x = left - sprite.width / 2; 
    }
    else if (sprite.x + sprite.width / 2 < left)
    { 
        sprite.x = right + sprite.width / 2; 
    } 
    if (sprite.y – sprite.height / 2 > bottom) 
    { 
        sprite.y = top – sprite.height / 2; 
    } 
    else if (sprite.y + sprite.height / 2 < top) 
    { 
        sprite.y = bottom + sprite.height / 2; 
    }
    

    摩擦力应用(正确方法): 

    speed = Math.sqrt(vx * vx + vy * vy); 
    angle = Math.atan2(vy, vx);
    
    if (speed > friction) { 
        speed -= friction; 
    } else { 
        speed = 0; 
    } 
    
    vx = Math.cos(angle) * speed; 
    vy = Math.sin(angle) * speed;
    

    摩擦力应用(简便方法): 

    vx *= friction; 
    vy *= friction;
    

  • 相关阅读:
    JavaScript(ASP)常用代码
    用JavaScript + jMail发邮件
    SQL语句导入导出大全
    C#编程方式执行包的任务
    匹配版本号
    c# web 页面帮定数据的 7中方式
    好书
    奇怪的异步调用,那位高手能帮忙看一下?
    vb6 调用c# 服务
    易犯的错误忘了初始化对象
  • 原文地址:https://www.cnblogs.com/alexlee85/p/1936203.html
Copyright © 2011-2022 走看看