actionscript - Determine if the mouse made a complete circle around a point -
i have game working on. trying detect if mouse has made complete 360 degree rotation around point. struggling logic though. full rotation can forwards or backwards dynamic start point.
what have work now:
so properties can added , start have current angle relative point (a sword.)
so
anglenow =
and
sword. properties can added. messing around properties direction angle moving in, start angle, etc...
i post code kind of obscure , incorrect.
can me out this? pseudo code good. makes sense... code
if (sword.motiondirection == const.direction_positive) { if (rotateangle >= sword.motioncurrent) { trace("good" + gamecounter); sword.motioncurrent = rotateangle; // update current } else { // switch directions trace("switch" + gamecounter); sword.motioncurrent = rotateangle; sword.motiondirection = const.direction_negative; sword.motionstart = rotateangle; } } rotateangle angle.
thanks.
another possible solution divide stage based on point circle , point mouse begins.
you can calculate line through mouse , point, perpendicular line in order form quadrants of stage.
in image, mouse square , point point. can tell direction mouse moves finding out quadrant enters. once mouse has entered each quadrant in correct order (1-4 or 4-1), know moment mouse enters 1st quadrant entered, have completed full circle.
example:
the mouse enters quadrant 1 (q1) first enters q2, q3, , q4. @ point, entering q1 again mouse have passed line started on , completed full circle.

//import mouse events import flash.events.mouseevent; //on whatever event want throw function check_for_circle var bound_q1:array = [0,90]; var bound_q2:array = [90,180]; var bound_q3:array = [180,270]; var bound_q4:array = [270,0]; var q1 = false; var q2 = false; var q3 = false; var q4 = false; function check_for_circle(event:mouseevent){ //calculate angle bounds each quadrant //add logic make sure degrees wrap @ 360 bound_q1[0]=//mouse start degree; bound_q1[1]=bound_q1[0]+90; bound_q2[0]=bound_q1[1]; bound_q2[1]=bound_q2[0]+90; bound_q3[0]=bound_q2[1]; bound_q3[1]=bound_q3[0]+90; bound_q4[0]=bound_q3[1]; bound_q4[1]=bound_q1[0]; } if(rotateangle>bound_q1[0] && rotateangle<bound_q1[1]/*mouse in q1*/){ if(q1 && q2 && q3 && q4){ //full circle! }else if(q1 && q2){ //this means turned around q4=false; q3=false; q2=false; } //we in q1 q1=true; } if(rotateangle>bound_q2[0] && rotateangle<bound_q2[1]/*mouse in q2*/){ if(q1 && q2 && q3 && q4){ //we started @ q4 , turned around q1=false; }else if(q1 && q2 && q3){ //we started @ q1 , turned around q3=false; q4=false; } //we in q2 q2=true; } if(rotateangle>bound_q3[0] && rotateangle<bound_q3[1]/*mouse in q3*/){ if(q1 && q2 && q3 && q4){ //we started @ q1 , turned around q4=false; }else if(q4 && q2 && q3){ //we started @ q4 , turned around q2=false; q1=false; } //we in q3 q3=true; } if(rotateangle>bound_q4[0] && rotateangle<bound_q4[1]/*mouse in q4*/){ if(q1 && q2 && q3 && q4){ //full circle! }else if(q4 && q3){ //this means turned around q1=false; q3=false; q2=false; } //we in q4 q4=true; }
Comments
Post a Comment