Flash에서 ActionScript3를 사용하여 커서를 따라 가면서 다른 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에 대해 container.x + (container.width/2)를 변경했습니다. 이러한 개체가 두 개있는 방법이 있는지 알고 계십니까? 나는 MC의 사본과 다른 변수를 가진 스크립트의 복사본을 만들려고 노력했지만 어떤 이유로 든 나는 오른쪽 엉망진창에 넣었다. – peroyomas
다시 container.x + container.width/4로 변경하고 모든 경우에 잘 작동합니다. – peroyomas