小球随机运动
2008-12-29 09:11
288 查看
帧循环(EnterFrame)
代码如下:
1 //Save as BallMove.as
2 package
3 {
4 import flash.display.Sprite;
5 import flash.events.Event;
6
7 public class BallMove extends Sprite
8 {
9 private var ball:Sprite;
10
11 public function BallMove ()
12 {
13 Init ();
14 }
15 public function Init ():void
16 {
17 ball=new Sprite();
18 addChild (ball);
19
20 ball.graphics.beginFill (0xffff00);
21 ball.graphics.drawCircle (0,0,5);
22 ball.graphics.endFill ();
23
24 ball.x=stage.stageWidth/2;
25 ball.y=stage.stageHeight/2;
26
27 ball.addEventListener (Event.ENTER_FRAME,Ball_EnterFrame);
28 }
29 private function Ball_EnterFrame (e:Event):void
30 {
31 ball.x+=(15-30*Math.random());
32 ball.y+=(15-30*Math.random());
33 }
34 }
35 }
代码如下:
1 //Save as BallMove.as
2 package
3 {
4 import flash.display.Sprite;
5 import flash.events.Event;
6
7 public class BallMove extends Sprite
8 {
9 private var ball:Sprite;
10
11 public function BallMove ()
12 {
13 Init ();
14 }
15 public function Init ():void
16 {
17 ball=new Sprite();
18 addChild (ball);
19
20 ball.graphics.beginFill (0xffff00);
21 ball.graphics.drawCircle (0,0,5);
22 ball.graphics.endFill ();
23
24 ball.x=stage.stageWidth/2;
25 ball.y=stage.stageHeight/2;
26
27 ball.addEventListener (Event.ENTER_FRAME,Ball_EnterFrame);
28 }
29 private function Ball_EnterFrame (e:Event):void
30 {
31 ball.x+=(15-30*Math.random());
32 ball.y+=(15-30*Math.random());
33 }
34 }
35 }
相关文章推荐
- H5 canvas 小demo之小球的随机运动
- JavaScript彩色小球随机运动的效果分享
- 背景小球动画,飘飞小雪花,随机点运动
- Cocos2d入门--3--小球运动
- Swift - 加速传感器(CoreMotion)的用法,小球加速运动并反弹样例
- 不同图形随机的运动
- 【html5】如何用Html5中的canvas模拟小球三维运动动画呢?
- 基于Windows API的粒子随机运动C++实现
- 物理模拟小球运动
- cocos2d-x 3.2 物理小游戏教程3 block it 小球的运动 墙壁的隐藏
- Windows Store App JavaScript 开发:小球运动示例
- Java_Swing实现小球沿正弦曲线运动的代码
- Cocos2d-x实战项目开发:运动的小球
- week4_motion_of_ball_1(小球运动)——改进
- 安卓案例-跟随手指运动的小球
- Unity 小球在两点之间往返运动
- 小球随机出现在屏幕
- Js实现简单的小球运动特效
- java实现随机动态的小球
- [ActionScript 3.0] AS3.0 对象在矩形范围随机运动