as3 sprite
如何获得动态创建图形sprite的坐标(在场景中的坐标)varmySprite:sprite=newsprite();mySprite.graphics.lineStyl...
如何获得动态创建图形sprite的坐标(在场景中的坐标)
var mySprite:sprite = new sprite();
mySprite.graphics.lineStyle(1,0x000000,1);
mySprite.graphics.moveTo(100,100);
mySprite.graphics.lineTo(200,200);
trace(mySprite.x.toString() + "," + mySprite.x.toString() + "|" +
mySprite.width.toString() + "," + mySprite.height.toString());
结果输出为0,0|100,100
我想获得mySprite在场景中的位置,但只能得到mySprite在mv中的相对位置(默认为(0,0)),请问要怎么办?
PS:首先感谢各位的回答,如果有正确答案马上加分 展开
var mySprite:sprite = new sprite();
mySprite.graphics.lineStyle(1,0x000000,1);
mySprite.graphics.moveTo(100,100);
mySprite.graphics.lineTo(200,200);
trace(mySprite.x.toString() + "," + mySprite.x.toString() + "|" +
mySprite.width.toString() + "," + mySprite.height.toString());
结果输出为0,0|100,100
我想获得mySprite在场景中的位置,但只能得到mySprite在mv中的相对位置(默认为(0,0)),请问要怎么办?
PS:首先感谢各位的回答,如果有正确答案马上加分 展开
2个回答
展开全部
import flash.display.Sprite;
import flash.geom.Point;
var mySprite:Sprite = new Sprite();
mySprite.graphics.lineStyle(1,0x000000,1);
mySprite.graphics.moveTo(100,100);
mySprite.graphics.lineTo(200,200);
var mv:Sprite=new Sprite();
var p:Point=new Point(0,0);
mySprite.x=30;
mySprite.y=30;
mv.addChild(mySprite);
mv.x=20;
mv.y=20;
addChild(mv);
trace("mc x:"+mySprite.x+" y:"+mySprite.y);
trace("parent x:"+mySprite.parent.x+" y:"+mySprite.parent.y);
trace("把元件上的坐标转为舞台坐标:"+mySprite.localToGlobal(p));
结果:
mc x:30 y:30
parent x:20 y:20
把元件上的坐标转为舞台坐标:(x=50, y=50)
另外说一下,toString()方法系统会自动调用
import flash.geom.Point;
var mySprite:Sprite = new Sprite();
mySprite.graphics.lineStyle(1,0x000000,1);
mySprite.graphics.moveTo(100,100);
mySprite.graphics.lineTo(200,200);
var mv:Sprite=new Sprite();
var p:Point=new Point(0,0);
mySprite.x=30;
mySprite.y=30;
mv.addChild(mySprite);
mv.x=20;
mv.y=20;
addChild(mv);
trace("mc x:"+mySprite.x+" y:"+mySprite.y);
trace("parent x:"+mySprite.parent.x+" y:"+mySprite.parent.y);
trace("把元件上的坐标转为舞台坐标:"+mySprite.localToGlobal(p));
结果:
mc x:30 y:30
parent x:20 y:20
把元件上的坐标转为舞台坐标:(x=50, y=50)
另外说一下,toString()方法系统会自动调用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询