ballgrav
♥0 |
Line 41 |
Modified 2012-06-19 05:28:33 |
MIT License
archived:2017-03-30 09:13:36
ActionScript3 source code
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qXo1
*/
// forked from honekingu's 宿題:自由落下。
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
public class FlashTest extends Sprite {
private var ball:Sprite
private var a:Number//加速
private var ao:Number//1フレーム毎の加速度
private var v:Number//速度
private var speed:TextField = new TextField()
public function FlashTest() {
// write as3 code here..
ball = new Sprite()
ball.graphics.beginFill(0xFFFFFF * Math.random())
ball.graphics.drawCircle(0,0,16);
ball.graphics.endFill();
ball.y=0
ball.x=Math.random()*433+16
v = 0//初速度
a = 5.0//加速度
ao = a/30
addChild(ball)
addEventListener(Event.ENTER_FRAME,freefall)
addChild(speed)
}
public function freefall(event:Event):void{
if(ball.y+ball.height/2>stage.stageHeight){
ball.y=stage.stageHeight-ball.height/2;
v=-v;
}
if(ball.y<-8){
ball.graphics.clear();
ball.graphics.beginFill(0xFFFFFF * Math.random())
ball.graphics.drawCircle(0,0,16);
ball.graphics.endFill();
}
ball.y += v
v += ao
speed.text = "Speed:"+Math.floor(v)
}
}
}