ball.as

来自「我在08年11月利用flex3.0 mxml和as3.0设计的一个3D相册,用到」· AS 代码 · 共 55 行

AS
55
字号
package {	//Remember? Haha. I wish I can use similar way to solve bounce from edge.	//but this failed.	//and I realized that mxml and actionscript are not same.	//so I changed mind and started to reasearch NodeGarden.as and tried to find some solution.	import flash.display.Sprite;		public class Ball extends Sprite 	{		public var radius:Number;		private var color:uint;		public var vx:Number = 0;		public var vy:Number = 0;						public var bottom:Number;			public var ay:Number = .5; //acceleration in y				public var bounceFactor:Number = 0.7;							public function Ball(radius:Number=40, color:uint=0xff0000) {			this.radius = radius;			this.color = color;			init();		}				public function setInitialConditions(x:Number, y:Number, vy:Number):void {		this.x = x; this.y = y; this.vy = vy;			}				public function setBottomBounceLimit(b:Number):void{		bottom=b;		//the way to let Big Blue Ball bounce from bottom. 	}								public function init():void {			graphics.beginFill(color);			graphics.drawCircle(0, 0, radius);			graphics.endFill();		}				public function advance( ):void {		vy += ay; //Calculate velocity		y += vy;   //Calculate position				if(y + height > bottom) {			y = bottom - height;			vy *= -1*bounceFactor;		}					}}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?