zoukankan      html  css  js  c++  java
  • Draw Circle 沿着圆运动~

    package {
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Sprite;
    public class Test extends Sprite {
    //计数器
    private var vx:Number=0;
    private var vy:Number=0;
    ///////////////////////////
    private var boo:Boolean=true;
    //移动速度
    private var xspeed:Number=0.05;
    private var yspeed:Number=0.05;
    //起始点 (半径大小)
    private var xpoint:Number=stage.stageWidth/2+25;
    private var ypoint:Number=stage.stageHeight/2;
    //圆心
    private var X:Number=stage.stageWidth/2;
    private var Y:Number=stage.stageHeight/2;
    //半径 公式:半径=开方((X1-X2)的平方+(Y1-Y2)的平方)
    private var r:Number=Math.sqrt((X-xpoint)*(X-xpoint)+(Y-ypoint)*(Y-ypoint));
    public function Test():void {
    init();
    }
    private function init():void {
    addEventListener(Event.ENTER_FRAME,enterhs);
    stage.addEventListener(MouseEvent.CLICK,clickhs);
    }
    private function enterhs(evt:Event):void {
    this.graphics.lineStyle(1,0x000000,1);
    this.graphics.moveTo(xpoint,ypoint);
    ///////////公式:起始点X坐标=圆心X坐标+COS(移动速度)*半径

    vx+=xspeed
    vy+=yspeed
    trace(vx)
    xpoint=X+Math.cos(vx)*r;
    ypoint=Y+Math.sin(vy)*r;
    trace(Math.round(xpoint)+"======================XS")
    this.graphics.lineTo(xpoint, ypoint);
    //this.graphics.drawCircle(xpoint,ypoint,50);
    if(Math.round(xpoint)==25)
    removeEventListener(Event.ENTER_FRAME,enterhs);
    }
    private function clickhs(evt:MouseEvent):void {
    if (boo) {
    boo=false;
    removeEventListener(Event.ENTER_FRAME,enterhs);
    } else {
    boo=true;
    addEventListener(Event.ENTER_FRAME,enterhs);
    }
    }
    }
    }

  • 相关阅读:
    Office加载项安装
    Office加载项
    centos部署vue项目
    centos系统下安装Nginx
    MongoDB 安装笔记
    CDN基本工作过程
    前端常见跨域解决方案(全)
    JS 扁平化(flatten) 数组
    console.log 打印的值不准确
    arr.flat(Infinity)数组扁平化
  • 原文地址:https://www.cnblogs.com/flashweb/p/3526448.html
Copyright © 2011-2022 走看看