我试图让球落在舞台上,然后在另一个物体撞击时改变方向。在这种情况下,球落在滑道上,并假设将滑块向下滚动到舞台的底部。然而,在它继续向下滑动之前,它会跳到另一个位置,然后向下滑动。我不能指责问题。我还希望它停在左下角而不是中心。你能帮我解决一下吗?
以下是演示此问题的代码和Gif。我使用BitmapData hitTest
事件监听器来生成影响效果。并且我使用localToGlobal
变量来查找要在补间中使用的球的位置以改变方向。
import fl.transitions.Tween;
import fl.transitions.easing.*;
var blueClip: objct2 = new objct2();
addChild(blueClip);
//blueClip.x = 196;
//blueClip.y = 73;
var tweenY: Tween = new Tween(blueClip, "y", Regular.easeIn, 73, 0, 0, false);
var tweenX: Tween = new Tween(blueClip, "x", Strong.easeIn, 196, 0, 0, false);
var redRect: Rectangle = redClip.getBounds(this);
var redClipBmpData = new BitmapData(redRect.width, redRect.height, true, 1);
redClipBmpData.draw(redClip);
var blueRect: Rectangle = blueClip.getBounds(this);
var blueClipBmpData = new BitmapData(blueRect.width, blueRect.height, true, 1);
blueClipBmpData.draw(blueClip);
Button.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event: MouseEvent): void {
var tweenY: Tween = new Tween(blueClip, "y", Regular.easeIn, 100, 400, 1, true);
addEventListener(Event.ENTER_FRAME, enterFrame);
}
function enterFrame(e: Event): void {
if (redClipBmpData.hitTest(new Point(redClip.x, redClip.y),
255,
blueClipBmpData,
new Point(blueClip.x, blueClip.y),
255
)) {
var yourMC: DisplayObject = blueClip;
var point1: Point = yourMC.localToGlobal(new Point(yourMC.getRect(yourMC).x, yourMC.getRect(yourMC).y));
var point2: Point = yourMC.localToGlobal(new Point(yourMC.getRect(yourMC).x + yourMC.getRect(yourMC).width, yourMC.getRect(yourMC).y + yourMC.getRect(yourMC).height));
var alef: Number = point1.x; //x position of the object.
var bet: Number = point1.y; //y position of the object.
//var gimel: Number = point2.x - point1.x; //width of the object.
//var daled: Number = point2.y - point1.y; //height of the object.
redClip.filters = [new GlowFilter()];
var tweenY: Tween = new Tween(yourMC, "y", Regular.easeIn, alef, 392, 1, true);
var tweenX: Tween = new Tween(yourMC, "x", Regular.easeIn, bet, 0, 1, true);
//tweenY.stop();
trace("hit");
trace("x" + alef);
trace("y" + bet);
} else {
redClip.filters = [];
//trace("miss");
}
}
tweenY.stop();
trace(tweenY.stop);
stop();
答案 0 :(得分:0)
我明白了。我不得不删除听众,X和Y混淆了,现在已经纠正了。
removeEventListener(Event.ENTER_FRAME, enterFrame);
var yourMC: DisplayObject = blueClip;
var point1: Point = yourMC.localToGlobal(new Point(yourMC.getRect(yourMC).x, yourMC.getRect(yourMC).y));
var point2: Point = yourMC.localToGlobal(new Point(yourMC.getRect(yourMC).x + yourMC.getRect(yourMC).width, yourMC.getRect(yourMC).y + yourMC.getRect(yourMC).height));
var alef: Number = point1.x; //x position of the object.
var bet: Number = point1.y; //y position of the object.
redClip.filters = [new GlowFilter()];
var tweenXa: Tween = new Tween(blueClip, "x", Regular.easeIn, alef, 0, 1, true);
var tweenYb: Tween = new Tween(blueClip, "y", Regular.easeIn, bet, 392, 1, true);
//tweenY.stop();
trace("hit");
//trace("x" + alef);
//trace("y" + bet);
} else {
redClip.filters = [];
//trace("miss");
}
}