flash actionscript3.0
发布时间:2020-12-15 06:50:46 所属栏目:百科 来源:网络整理
导读:今天学习下圆运动 以太阳 地球 月亮为例 主要内容是 ?? ??? ??? ???? earth.x=sun.x+120*Math.cos(n); ?? ??? ??? ??? ?earth.y=sun.y+120*Math.sin(n); sun.x sun.y是圆的中心点 120是圆的半径 n 是角度0~2PI package {import flash.display.Sprite;import
今天学习下圆运动 以太阳 地球 月亮为例 主要内容是 ?? ??? ??? ???? earth.x=sun.x+120*Math.cos(n); sun.x sun.y是圆的中心点 120是圆的半径 n 是角度0~2PI package { import flash.display.Sprite; import flash.events.*; import flash.geom.*; import flash.filters.*; import flash.display.DisplayObject; public class yuan extends Sprite { private var sun,earth,moon:Sprite=new Sprite();//创建容器 private var centerX:Number=stage.stageWidth/2; private var centerY:Number=stage.stageHeight/2; private var j:Number=0; private var n:Number=0; public function yuan() { sun=new Sprite(); addChild(sun); sun.graphics.beginFill(0xffcc00); sun.graphics.drawCircle(0,30); sun.graphics.endFill(); //太阳位置在舞台中间 sun.x=centerX; sun.y=centerY; sun.z=0; //对太阳使用模糊 sun.filters=[new BlurFilter(20,20,BitmapFilterQuality.HIGH)]; moon=new Sprite(); addChild(moon); moon.graphics.beginFill(0xcccccc); moon.graphics.drawCircle(0,4); moon.graphics.endFill(); moon.x=0; moon.y=0; moon.z=0; earth=new Sprite(); addChild(earth); earth.graphics.beginFill(0x0033FF); earth.graphics.drawCircle(0,15); earth.graphics.endFill(); earth.x=0; earth.y=0; earth.z=0; //加入帧事件 addEventListener(Event.ENTER_FRAME,Run); } public function Run(e:Event):void{ //地球相对于太阳位置 n+=0.05; earth.x=sun.x+120*Math.cos(n); earth.y=sun.y+120*Math.sin(n); if(n>=6.28) n=0;//6.28是2个PI意思 //月亮相对于地球位置 j+=0.2; moon.x=earth.x+30*Math.cos(j); moon.y=earth.y+30*Math.sin(j); if(j>=6.28) j=0; } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容