StarlingManual:透视坐标

来自Starling中文站
跳转到: 导航, 搜索

轴心点是个传统显示列表不会有的特性。在Starling中,显示对象有两个额外的属性:pivotX和pivotY.轴心点(或称起始点(origin),原点(root),锚点)定义了Starling显示对象坐标系统的原点。 默认时,轴心点是(0,0);在一个图片中,是在左上角。大多数时候这是我们想要的。但是有时候,我们希望原点在别的地方,比如想要绕图片的中点旋转图片。到现在为止,我们必须把显示对象放到一个容器里面来实现:

var image:Image = new Image(texture);
 
var sprite:Sprite = new Sprite();
image.x = -image.width / 2.0;
image.y = -image.height / 2.0;
sprite.addChild(image);
 
sprite.rotation = deg2rad(45); // -> rotate around center

不足为奇,as程序员一直在这么做。但是有人会争论这一个简单的功能用了这么多代码。有了轴心点,代码会精简成这样:

var image:Image = new Image(texture);
image.pivotX = image.width  / 2.0;
image.pivotY = image.height / 2.0;
image.rotation = deg2rad(45); // -> rotate around center

再也不需要显示容器了!还是坚持前几章的比喻:轴心点定义了显示对象放到父容器中时,像大头针一样穿过的点。以上代码将显示对象轴心点移动到了中心。


翻译:杨旺(peter4431)

个人工具
名字空间

变换
操作
导航
Starling中文资料
Starling原创教程
论坛
友链
工具箱