• 绘制刚体(二)


    与第一个绘制刚体例子一样的,在舞台上点击鼠标拖动,绘制刚体。舞台上有两个RadioButton,用来选择是画矩形的刚体还是圆形的刚体。

    下面是mouseUp事件监听处理函数:

        private function onUp(e:MouseEvent):void 
    		{
    			_bodyContainer.graphics.clear();
    			_isDown = false;
    			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
    			stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
    			
    			var endx:int = stage.mouseX;
    			var endy:int = stage.mouseY;
    			
    			var int;
    			var height:int;
    			
    			var random:int = 1 + Math.floor(Math.random()*10);
    			if (_isDrawRect)
    			{
    				if (endx<_initx)
    				{
    					var tempx:int = _initx;
    					_initx = endx;
    					endx = tempx;
    				}
    				if (endy<_inity)
    				{
    					var tempy:int = _inity;
    					_inity = endy;
    					endy = tempy;
    				}
    				width = Math.abs(endx - _initx);
    				height = Math.abs(endy - _inity);
    				if (width == 0 || height == 0) return;
    				var myRect:Rect = new Rect(width, height, new Point(_initx + width / 2, _inity + height / 2), new Point(), new MyRect(), _bodyContainer);
    				(myRect.displayObject as MovieClip).gotoAndStop(random);
    				_actors.push(myRect);
    			}
    			else
    			{
    				width = Math.abs(endx - _initx);
    				height = Math.abs(endy - _inity);
    				if (width == 0 || height == 0) return;
    				var dist:Number = Math.sqrt(width * width + height * height);
    				trace(dist, width, height);
    				var myCircle:Ball = new Ball(dist, new Point(_initx, _inity), new Point(), new MyCircle(), _bodyContainer);
    				(myCircle.displayObject as MovieClip).gotoAndStop(random);
    				_actors.push(myCircle);
    			}
    		}
    

  • 相关阅读:
    《试题库管理系统的设计与实现》11
    转 windows10安装docker
    转 linux 安装docker
    Centos7 离线安装RabbitMQ,并配置集群
    Linux配置Redis主从
    CENTOS7下安装REDIS
    sql删除相同数据(无主键)
    mybatis中 <if test=>等于的条件怎么写
    java 日期获取,每月一号,每周一
    Oracle中merge into的使用
  • 原文地址:https://www.cnblogs.com/ywxgod/p/1713987.html
Copyright © 2020-2023  润新知