Taurayi先生,您提供的解决方案真是太棒了。但我不想在进入框架中这样做。我只是补间对象以旋转到随机位置。所以让我知道轮换的条件。我的意思是对象应该向随机点旋转。例如。如果(dx < 0){
dx += 360;
dy += 360;
angl = Math.atan(dy/dx) + deg2rad(90)
InsectsVector[i].rotation = angl;
}
if(dx >= 360){
dx -= 360;
dy -= 360;
angl = Math.atan(dy/dx) + deg2rad(90)
InsectsVector[i].rotation = angl;
}
if ( dy > 180 )
{
dx -= 360;
dy -= 360
angl = Math.atan(dy/dx) + deg2rad(-90);
InsectsVector[i].rotation = angl;
}
if ( dx < -180 )
{
dx += 360;
dy += 360;
angl = Math.atan(dy/dx) + deg2rad(90)
InsectsVector[i].rotation = angl;
}
上面的这种情况在下面的编码中不能正常工作。所以请让我知道这一点。
Please its very urgent dudes. And thanks in advance for replying.
private function InsectsRandPos():void{
randNum_1 = uint(Math.random()*50);
for (var i:uint=0; i < InsectsVector.length; i++){
while(InsecNode.indexOf(randNum_1) != -1){
randNum_1 = uint(Math.random()*50);
}
InsecNode[i] = randNum_1;
randPointForInsec = nodeContainer.getNodePostion(InsecNode[i]);
if(spNode != InsecNode[i]){
InsectsVector[i].visible = true;
nodeContainer.addChild(InsectsVector[i]);
var dx:Number = randPointForInsec.x - InsectsVector[i].x ;
var dy:Number = randPointForInsec.y - InsectsVector[i].y ;
var angl:Number = Math.atan(dy/dx) + deg2rad(90);
InsectsVector[i].rotation = angl; // (angl*-1)+180;
if( dx < 0){
dx += 360;
dy += 360;
angl = Math.atan(dy/dx) + deg2rad(90)
InsectsVector[i].rotation = angl;
}
if(dx >= 360){
dx -= 360;
dy -= 360;
angl = Math.atan(dy/dx) + deg2rad(90)
InsectsVector[i].rotation = angl;
}
if ( dy > 180 )
{
dx -= 360;
dy -= 360
angl = Math.atan(dy/dx) + deg2rad(-90);
InsectsVector[i].rotation = angl;
}
if ( dx < -180 )
{
dx += 360;
dy += 360;
angl = Math.atan(dy/dx) + deg2rad(90)
InsectsVector[i].rotation = angl;
}
var InsectTwee:Tween = new Tween(InsectsVector[i], 5, Transitions.LINEAR );
InsectTwee.animate("x", randPointForInsec.x);
InsectTwee.animate("y", randPointForInsec.y);
Starling.juggler.add(InsectTwee);
}
else if(spNode == InsecNode[i]){
var obj:Object = new Object();
obj = InsectsVector[i];
obj.visible = false;
trace("obj .name ..."+obj + " InsectsVector[i] :"+InsectsVector[i])
}
}
}