|
|
|
#1 |
|
Senior Member
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
|
Hit Testing my newest challenge...!!
Hi guys
i'm using a motion dection system to control an interface and instead of doing each hit test on it's own i wanted a function which would make it simplier to code... instead of righting a million and 1 if statements.. Well this isn't producing any errors but i'm sure it's wrong because it's not working...so i'm just checking in with you guys to see if i'm writing my hit tests and variables right... the hover function needs to relate to what ever i call it in the paramaters when i call the function... anyhelp would be most grateful.. Andy Code:
//HIT-TESTFUNCTIONS
function hitAndHover(target,hover):Void{
var hover:Number=0;
if (trackdot.hitTest(target)){
hover++;
target.gotoAndPlay("OverState");
trace(hover);
}else{
target.gotoAndPlay("NormalState")
hover=0;
}
};
//Activation Function
function Thumbs_hitAndPlay(target,sName,sPos):Void{
if (hover==20) {
_root.populateCONTENT(sName,sPos);
target.gotoAndPlay("Selected");
trace("Activated");
hover=0;
}
};
//CALLING THE FUNCTIONS.. THESE ARE ON THE TIME LINE WHERE THEY ARE MEANT TO ACTIVATE IN THIS CASE INSPIRE..
//THUMB1
//Here i'm trying to tell it to in laymans terms.. if trackdot (which is the movie clip which is moved via motion detection) hits thumb1 start counting hover1
_root.hitAndHover(thumb1_mc,hover1);
//Here i'm trying to tell it to in laymans terms again to if trackdot has hit thumb1 for hover1 count 20 then activate function populateContent with the
Inspire array at 0.
_root.Thumbs_hitAndPlay(hover1,thumb1_mc,"Inspire",0);
//THUMB2
_root.hitAndHover(thumb2_mc,hover2);
_root.Thumbs_hitAndPlay(hover2,thumb2_mc,"Inspire",1);
//THUMB3
_root.hitAndHover(thumb3_mc,hover3);
_root.Thumbs_hitAndPlay(hover3,thumb3_mc,"Inspire",2);
//THUMB4
_root.hitAndHover(thumb4_mc,hover4);
_root.Thumbs_hitAndPlay(hover4,thumb4_mc,"Inspire",3);
//THUMB5
_root.hitAndHover(thumb5_mc,hover5);
_root.Thumbs_hitAndPlay(hover5,thumb5_mc,"Inspire",4);
//THUMB6
_root.hitAndHover(thumb6_mc,hover6);
_root.Thumbs_hitAndPlay(hover6,thumb6_mc,"Inspire",5);
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
|
Update well i've tried a few new things but still no luck... any ideas?
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
|
UPDATE : STILL NOT WORKING the bummer although the code is a lot cleaner now.. but i still don't understand what i'm doing wrong...
here is the whole code.. including the motion tracking code Code:
//Motion tracker
import flash.display.*;
import flash.geom.*;
// INIT
trackdot.inTrans = false;
setInterval(detection, 110);
ScreenSizeX = 800.0;
ScreenSizeY = 480.0;
// Connect the webcam
cam = Camera.get();
this.vid.attachVideo(cam);
now = new BitmapData(cam.width, cam.height);
before = new BitmapData(cam.width, cam.height);
rect = new Rectangle(0, 0, cam.width, cam.height);
trace("cam.width="+cam.width+" cam.height="+cam.height);
sizeDif = ScreenSizeX / cam.width;
pt = new Point(0, 0);
// Show The MonoColor image
//coverRect = new Rectangle(0, 0, 130, 120);
function detection() {
if (!cam.muted) {
now.draw(vid);
now.draw(before, new Matrix(), new ColorTransform(), 'difference');
now.threshold(now, rect, pt, '>', 0xff333333, 0xffff0000);
now.fillRect(coverRect, 0xff000000);
before.draw(vid);
//
re = now.getColorBoundsRect(0xffffffff, 0xffff0000, true);
//trace(r.toString());
ColorChange = now.threshold(now, re, new Point(re.x, re.y), '==', 0xffff0000, 0xffff0000);
//trace(ColorChange);
if (re.x<160 && ColorChange>10) {
trackdotNewY = (re.height/2+re.y)*sizeDif;
}
if (re.y<120 && ColorChange>10) {
trackdotNewX = re.width/2+re.x;
trackdotNewX = ScreenSizeX-(trackdotNewX*sizeDif);
}
tweenPlayer(trackdotNewY, trackdotNewX);
}
}
// display the motion detection bitmap
bitmaporb_mc.attachBitmap(now, 10);
vx = 75;
vy = 75;
//r = tackdot._width/2;
//HIT-TESTFUNCTIONS
function hitAndHover(target, hover):Void {
_root[hover] = 0;
if (trackdot.hitTest(target)) {
_root[hover]++;
target.gotoAndPlay("OverState");
trace("Hovertimer"+_root[hover]);
} else {
target.gotoAndPlay("NormalState");
_root[hover] = 0;
trace("NOT..HOVER");
}
}
function Thumbs_hitAndPlay(target,hover,sName,sPos):Void{
if (_root[hover]==20) {
_root.populateCONTENT(sName,sPos);
target.gotoAndPlay("Selected");
trace("Activated");
_root[hover] = 0;
}
};
function tweenPlayer(param, param2) {
easeType = mx.transitions.easing.Regular.easeOut;
var mc = trackdot;
if (mc.inTrans == false) {
//mc.inMovement = true;
var begin = mc._y;
var beginX = mc._x;
var end = param;
//var end = mc._y+(random(10)-5);
var time = 0.6;
ballTween = new mx.transitions.Tween(mc, "_y", easeType, begin, end, time, true);
ballTween = new mx.transitions.Tween(mc, "_x", easeType, beginX, param2, time, true);
ballTween.onMotionFinished = function() {
mc.inTrans = false;
};
}
}
Now here is where the function are called.. in a sep frame on the inspire marker.. Code:
stop(); //INIT _root.populateInspireThumbs(); //CALL FUNCTIONS IN INSPIRE FRAME //THUMB1 onEnterFrame=hitAndHover(thumb1_mc,"hover1"); onEnterFrame=Thumbs_hitAndPlay(thumb1_mc,"Inspire",0); //THUMB2 onEnterFrame=hitAndHover(thumb2_mc,"hover2"); onEnterFrame=Thumbs_hitAndPlay(thumb2_mc,"Inspire",1); //THUMB3 onEnterFrame=hitAndHover(thumb3_mc,"hover3"); onEnterFrame=Thumbs_hitAndPlay(thumb3_mc,"Inspire",2); //THUMB4 onEnterFrame=hitAndHover(thumb4_mc,"hover4"); onEnterFrame=Thumbs_hitAndPlay(thumb4_mc,"Inspire",3); //THUMB5 onEnterFrame=hitAndHover(thumb5_mc,"hover5"); onEnterFrame=Thumbs_hitAndPlay(thumb5_mc,"Inspire",4); //THUMB6 onEnterFrame=hitAndHover(thumb6_mc,"hover6"); onEnterFrame=Thumbs_hitAndPlay(thumb6_mc,"Inspire",5); Andy. |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
|
Update.. Still Stuggling... But getting there will keep reporting on progress.
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
|
update.. it's gonnabe a long night to get this done....
.got the hit testing working now ya... it's not great but it's getting there.. even got roll over states working 2..still it's gonna be a long night 2night ... want to get the video player finished at least.. Andy |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|