최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

   포물선 운동과 공


step06 : 그림자 따라다니기


그림자가 공을 계속 따라다니려면 "그림자.x = 공.x" 로 간단하게 처리하면 된다.



소스)


step06.fla


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;
						  }
					  });




결과)




댓글