티스토리 뷰
포물선 운동과 공
step06 : 그림자 따라다니기
그림자가 공을 계속 따라다니려면 "그림자.x = 공.x" 로 간단하게 처리하면 된다.
소스)
import flash.events.Event;
import flash.display.Sprite;
import flash.filters.BlurFilter;
import flash.filters.BitmapFilterQuality;
var g:Number = 1;
var vy:Number = 8;
var vx:Number = 10;
var rot:Number = vx;
var bottom:Number = stage.stageHeight - (ball.height/2) - 20;
var _eclipse:Sprite = new Sprite();
_eclipse.graphics.beginFill(0x000000, 0.7);
_eclipse.graphics.drawEllipse(-ball.width/2, -20/2, ball.width, 20);
_eclipse.graphics.endFill();
_eclipse.x = ball.x;
_eclipse.y = bottom + (ball.height/2) + 10;
var blur:BlurFilter = new BlurFilter(10, 5, BitmapFilterQuality.HIGH);
_eclipse.filters = [blur];
addChild(_eclipse);
var num:int = this.numChildren;
this.setChildIndex(ball, num-1);
//addChild(ball);
this.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
vy += g;
ball.y += vy;
ball.x += vx;
ball.rotation += rot;
_eclipse.x = ball.x;
if( ball.x > stage.stageWidth - (ball.width/2) ) {
ball.x = stage.stageWidth - (ball.width/2);
vx = -vx;
rot = -rot;
}
if( ball.x < (ball.width/2) ) {
ball.x = ball.width/2;
vx = -vx;
rot = -rot;
}
if( ball.y > stage.stageHeight - (ball.height/2) ) {
ball.y = stage.stageHeight - (ball.height/2);
vy = -vy;
}
if( ball.y < (ball.height/2) ) {
ball.y = ball.height/2;
vy = -vy;
}
});
결과)
'■ 개발관련 ■ > 산수와 알고리즘' 카테고리의 다른 글
| 포물선 운동과 공 step08:그림자의 투명도와 크기 변화 (0) | 2014.08.31 |
|---|---|
| 포물선 운동과 공 step07:그림자 사이즈 조절 (0) | 2014.08.31 |
| 포물선 운동과 공 step05:그림자 만들기 (0) | 2014.08.31 |
| 포물선 운동과 공 step04:공의 회전 (0) | 2014.08.31 |
| 포물선 운동과 공 step03:공에 수평운동 추가 (0) | 2014.08.31 |
댓글
step06.fla