绘制刚体(二)
与第一个绘制刚体例子一样的,在舞台上点击鼠标拖动,绘制刚体。舞台上有两个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 width: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); } }
作者:ywxgod
E-mail:给我发邮件
出处:http://ywxgod.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
E-mail:给我发邮件
出处:http://ywxgod.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。