📄 ball.as
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -