package {
import com.greensock.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class shieet extends Sprite
{
public function shieet()
{
var PosY:Number = Math.floor(Math.random()*(stage.stageHeight-30));
var PosX:Number = 0;
var PosX2:Number = 500;
var CircleBlue:MovieClip = new MovieClip();
CircleBlue.graphics.lineStyle(2, 0);
CircleBlue.graphics.beginFill(0x0000FF);
CircleBlue.graphics.drawCircle(PosX,PosY,30);
graphics.endFill();
addChild(CircleBlue);
PosY = Math.floor(Math.random()*(stage.stageHeight-30));
var CircleRed:MovieClip = new MovieClip();
CircleRed.graphics.lineStyle(2, 0);
CircleRed.graphics.beginFill(0xFF0000);
CircleRed.graphics.drawCircle(PosX2,100,30);
graphics.endFill();
addChild(CircleRed);
stage.addEventListener(MouseEvent.CLICK,move_circle);
function move_circle(event:MouseEvent):void {
TweenLite.to(CircleBlue,4, {x:PosX2, y:100});
}
}
}}
这是我将蓝色圆圈移动到红色圆圈的代码。
鼠标事件之前:https://api.monosnap.com/image/download?id=nLQQXmInSsSCqhRxjF2XaneWUpnVWm
鼠标事件后:https://api.monosnap.com/image/download?id=KhiUFE97lNbVkkSoVlxfsfyUeJM2v1
如您所见,红色圆圈的x轴设置为500,y轴设置为100. Tweenlite目标点设置为红色圆圈的x轴和100。 但它只是像X轴一样移动到X轴,y轴的行为很奇怪。看起来它从蓝色圆圈的当前位置移动到+100点,而不是从0移动到100。 我甚至不知道该做什么,尝试了很多东西。
答案 0 :(得分:0)
问题是红色和蓝色圆圈的原点仍然是0,0。试试这个......
package {
import com.greensock.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class shieet extends Sprite {
public function shieet() {
var PosY:Number = Math.floor(Math.random()*(stage.stageHeight-30));
var PosX:Number = 0;
var PosX2:Number = 500;
var CircleBlue:MovieClip = new MovieClip();
CircleBlue.graphics.lineStyle(2, 0);
CircleBlue.graphics.beginFill(0x0000FF);
CircleBlue.graphics.drawCircle(0,0,30);
graphics.endFill();
addChild(CircleBlue);
// Now that the graphic is on the center of the MC, move the MC, not the drawing.
CircleBlue.x = PosX;
CircleBlue.y = Math.floor(Math.random()*(stage.stageHeight-30));
PosY = Math.floor(Math.random()*(stage.stageHeight-30));
var CircleRed:MovieClip = new MovieClip();
CircleRed.graphics.lineStyle(2, 0);
CircleRed.graphics.beginFill(0xFF0000);
CircleRed.graphics.drawCircle(0,0,30);
graphics.endFill();
addChild(CircleRed);
CircleRed.x = PosX2;
CircleRed.y = 100;
stage.addEventListener(MouseEvent.CLICK,move_circle);
function move_circle(event:MouseEvent):void {
TweenLite.to(CircleBlue,4, {x:PosX2, y:100});
}
}
}
}