如何在ActionScript中的Actionscript 3中製作跟隨光標的MovieClip,但受限於其他MovieClip的不規則形狀?FLASH/AS3:圖中的光標仍然限制在不規則區域
編輯:這是有點什麼,我需要:
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
function follow(evt:MouseEvent){
if(container.hitTestPoint(mouseX, mouseY, true)) {
cursor.x = mouseX;
cursor.y = mouseY;
} else {
var dx:int = cursor.mouseX;
var dy:int = ;
cursor.x = dx;
cursor.y = cursor.mouseY;
}
}
我想做到的是,使光標MC還是「跟隨」光標當在容器外MC,但無法逃脫從中。
老AS2腳本做到這一點,但我不知道如何將它轉換:
onClipEvent (mouseMove) {
tX = _parent._xmouse;
// tX/tY are 'target' X/Y.
tY = _parent._ymouse;
if (_parent.constraintzone.hittest(tX, tY, true)) {
_x = tX;
_y = tY;
} else {
// and now the hurting begins
// get XY of center of constraint zone
cX = _parent.constraintzone._x;
// cX/cY are 'constrained' X/Y,
cY = _parent.constraintzone._y;
// found somewhere inside the constraint zone.
accuracy = 1;
// smaller = more accurate.
do {
dX = (tX-cX)/2;
// dX/dY are deltas to the midpoint between
dY = (tY-cY)/2;
// target XY and constrained XY.
if (_parent.constraintzone.hittest((tX-dX), (tY-dY), true)) {
cX += dX;
// midpoint is in; step out towards mouse.
cY += dY;
} else {
tX -= dX;
// midpoint is out; step in towards center.
tY -= dY;
}
// loop end.
// (dD > .5) is more accurate, (dX > 10) is less.
} while ((Math.abs(dX)>accuracy) || (Math.abs(dY)>accuracy));
_x = tX;
// we're done, set the final position.
_y = tY;
}
}
它確實有效,但我更改了container.x +(container.width/2)for(container.x + container.width)/ 2.你知道是否有辦法讓這些對象中的兩個對象?我曾經嘗試製作一個MC副本和一個帶有不同變量的腳本副本,但由於某種原因,我放在右邊的那個混亂起來。 – peroyomas 2010-06-04 05:08:22
我再次將其更改爲container.x + container.width/4,並且在我的所有情況下運行良好。 – peroyomas 2010-06-06 15:12:20