This is the original code:
// A shape to represent the tracking point
_target = new Shape();
_target.graphics.lineStyle(0, 0xFFFFFF);
_target.graphics.drawCircle(0, 0, 10);
addChild(_target);
addChild(round);
After test the array, lecturer decided to use manual calling to call out the movie clip because array cannot duplicate the element in it. And this is the code after edited by lecturer:
// A shape to represent the tracking point
_target = new Shape();
_target.graphics.lineStyle(0, 0xFFFFFF);
_target.graphics.drawCircle(0, 0, 10);
addChild(_target);
addChild(round1);
addChild(round2);
addChild(round3);
addChild(round4);
addChild(round5);
Everything went manual afterwards. Here are the codes for manually color changing for each movie clip:
private function changeColor(){
//random color value
col = Math.random()*0xffffff;
cTransform.color = col;
//round.transform.colorTransform = cTransform;
if(counter==1){
round1.transform.colorTransform = cTransform;
}else if(counter==2){
round2.transform.colorTransform = cTransform;
}else if(counter==3){
round3.transform.colorTransform = cTransform;
}else if(counter==4){
round4.transform.colorTransform = cTransform;
}else if(counter==5){
round5.transform.colorTransform = cTransform;
}
}
This is the random calling for the all types of splashing effects:
private function keyDownHandler(event : KeyboardEvent):void
{
if (event.keyCode==Keyboard.SPACE) {
//round.gotoAndPlay(2);
counter = Math.round(Math.random()*5)+1;
if(counter>5){
counter = 0;
}
trace("counter="+counter);
changeColor();
if(counter==1){
round1.gotoAndPlay(2);
trace("round1");
}
if(counter==2){
round2.gotoAndPlay(2);
trace("round2");
}
if(counter==3){
round3.gotoAndPlay(2);
trace("round3");
}
if(counter==4){
round4.gotoAndPlay(2);
trace("round4");
}
if(counter==5){
round5.gotoAndPlay(2);
trace("round5");
}
}
}
And below is the random x and y coordinate for the movie clip around the motion detection. It is seem random but actually it is actually manually random.
// Draw the motion bounds so we can see what the MotionTracker is doing
_bounds.graphics.clear();
_bounds.graphics.lineStyle(0, 0xFFFFFF);
_bounds.graphics.drawRect(_motionTracker.motionArea.x, _motionTracker.motionArea.y, _motionTracker.motionArea.width, _motionTracker.motionArea.height);
var x1:Number;
var y1:Number;
var x2:Number;
var y2:Number;
var x3:Number;
var y3:Number;
var x4:Number;
var y4:Number;
var x5:Number;
var y5:Number;
if(counter==1){
x1 = -50;
y1 = 0;
x2 = 20;
y2 = 45;
x3 = 50;
y3 = 10;
x4 = 0;
y4 = 100;
x5 = -10;
y5 = -10;
}else if(counter==2){
x1 = -10;
y1 = 10;
x2 = -50;
y2 = 30;
x3 = 70;
y3 = -25;
x4 = 30;
y4 = -5;
x5 = 0;
y5 = 24;
}else if(counter==3){
x1 = 70;
y1 = -10;
x2 = -30;
y2 = -32;
x3 = -5;
y3 = 45;
x4 = 55;
y4 = 10;
x5 = -60;
y5 = -10;
}else if(counter==4){
x1 = 20;
y1 = -50;
x2 = -5;
y2 = 15;
x3 = -40;
y3 = 10;
x4 = -25;
y4 = -10;
x5 = 40;
y5 = -100;
}else if(counter==5){
x1 = 0;
y1 = 65;
x2 = 50;
y2 = 0;
x3 = 20;
y3 = -20;
x4 = -35;
y4 = 20;
x5 = -10;
y5 = -5;
}
round1.x = _motionTracker.motionArea.x+x1+(_motionTracker.motionArea.width/2);
round1.y = _motionTracker.motionArea.y+y1+(_motionTracker.motionArea.height/2);
round2.x = _motionTracker.motionArea.x+x2+(_motionTracker.motionArea.width/2);
round2.y = _motionTracker.motionArea.y+y2+(_motionTracker.motionArea.height/2);
round3.x = _motionTracker.motionArea.x+x3+(_motionTracker.motionArea.width/2);
round3.y = _motionTracker.motionArea.y+y3+(_motionTracker.motionArea.height/2);
round4.x = _motionTracker.motionArea.x+x4+(_motionTracker.motionArea.width/2);
round4.y = _motionTracker.motionArea.y+y4+(_motionTracker.motionArea.height/2);
round5.x = _motionTracker.motionArea.x+x5+(_motionTracker.motionArea.width/2);
round5.y = _motionTracker.motionArea.y+y5+(_motionTracker.motionArea.height/2);
trace(round1.x);
trace(round1.y);
trace(round2.x);
trace(round2.y);
trace(round3.x);
trace(round3.y);
trace(round4.x);
trace(round4.y);
trace(round5.x);
trace(round5.y);
if ( !_motionTracker.hasMovement ) return;
}
After a long long coding time, here is finally the output for the installation! Wohoo! Thanks my lecturer Mr. Hafiz in helping me to make this thing works.
This still isn't the very last of my installation. I still need to program the code in Arduino to create virtual key for serial port so that SPACE key will be detected as well when vibration in detected. Add Oil!!!!
No comments:
Post a Comment