我正在使用Action script3.0来设置一个实例(MovieClip类)的动画,让它跟随鼠标正电子,这个实例的左上角跟随着鼠标。现在在左上角有一个十字,我猜鼠标会跟随这个十字,但我不能改变实例/原始对象中十字的位置。有人知道如何使该实例的中心跟随鼠标光标移动吗?感谢所有人在这个话题上的帮助。
发布于 2011-10-24 22:06:21
我使用这个代码。
import flash.display.Shape;
import flash.events.Event;
var easing:Number = .25; // inching coefficient
var sp:Shape = super.addChild(new Shape()) as Shape; // draw circle
sp.graphics.beginFill(0x0,.6);
sp.graphics.drawCircle(40,40,40);
sp.x = super.stage.stageWidth - sp.width >> 1;
sp.y = super.stage.stageHeight - sp.height >> 1;
super.stage.addEventListener(Event.ENTER_FRAME, update, false, 0, true);
function update(e:Event):void
{
var targetX:int = super.stage.mouseX - (sp.width >> 1);
var targetY:int = super.stage.mouseY - (sp.height >> 1);
sp.x += (targetX - sp.x) * easing;
sp.y += (targetY - sp.y) * easing;
}
发布于 2011-10-22 19:24:54
解决方案1:不要改变注册点的位置(十字)。将影片剪辑的内容更改为与中心位置对齐。试一下,你就会明白了。
解决方案2:使用偏移量移动实例。就像这样。
myInstance.x = mouseX - (myInstance.width * 0.5);
myInstance.y = mouseY - (myInstance.height * 0.5);
https://stackoverflow.com/questions/7858631
复制相似问题