zoukankan      html  css  js  c++  java
  • 一个鼠标拖出一个圆形的简单demo

    好久没上来过了·
    感觉自己都不属于这个圈子·~~




    这里讲一个鼠标画圆的例子
    其中最主要的是圆半径的求法
    小学数学勾股定理
    转换为计算机语言就是
    var radius:Number = Math.sqrt(Math.pow(thisWidth, 2) + Math.pow(thisHeight, 2));


    package
    {
     import flash.display.*;
     import flash.events.*;
     import flash.display.Sprite;
     import flash.events.*;
     public class CircleDemo extends Sprite
     {

      private var _sprite:Sprite;
      private var pos1:Object;
      private var pos2:Object;

      public function CircleDemo()
      {
       _sprite=new Sprite();
       this.stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
       this.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

       //drawMyCircle(100,100,50);
      }

      private function drawMyCircle(pointX:Number,pointY:Number,radius:Number):void
      {
       _sprite.graphics.beginFill(0x88FB00,0.4);
       _sprite.graphics.lineStyle(2,0xFFFF00);     
       _sprite.graphics.drawCircle(pointX,pointY,radius);
       _sprite.graphics.endFill();
       this.addChild(_sprite);
       _sprite.addEventListener(MouseEvent.CLICK, clickHandler);
      }

      private function mouseDownHandler(event:MouseEvent):void
      {
       pos1 = {x:event.stageX, y:event.stageY};
      }


      private function mouseUpHandler(event:MouseEvent):void
      {
       pos2 = {x:event.stageX, y:event.stageY};

       var thisWidth:Number = (pos2.x - pos1.x);
       var thisHeight:Number = (pos2.y - pos1.y);
       var radius:Number = Math.sqrt(Math.pow(thisWidth, 2) + Math.pow(thisHeight, 2));
       drawMyCircle(pos1.x,pos1.y,radius);
      }

      private function clickHandler(event:MouseEvent):void
      {
       var thisMC:MovieClip = event.currentTarget as MovieClip;
       thisMC.graphics.clear();
      }
     }
    }


     

    噢耶游戏是中国最大的轻社交游戏开发商,致力于手机页游的研发及推广业务。我们首创性地提出了HTML5游戏中心思路,在第三方App 中嵌入式休闲游戏,为开发者提供了全新的应用内游戏解决方案。
  • 相关阅读:
    面经补充
    一些杂项
    leetcode整理
    缓存问题及相关解决策略
    4.10 面经补充
    合并区间(二维数组与列表的转换)
    1.4任务
    jvm虚拟机笔记<八> 线程安全与锁优化
    jvm虚拟机笔记<七> 内存模型与线程
    jvm虚拟机笔记<六> 运行期优化
  • 原文地址:https://www.cnblogs.com/yintian2/p/1571632.html
Copyright © 2011-2022 走看看