gpt4 book ai didi

flash - AS3 如何从显示对象获取定位点(枢轴、注册点)位置

转载 作者:行者123 更新时间:2023-12-02 07:34:58 25 4
gpt4 key购买 nike

我要获取相对于 DisplayObject 的 anchor

例子: enter image description here

// HOW GET THIS VALUES IN CODE
Object height = 90px
Object width = 40px

anchor point X = 20px
anchor point Y = 72px
//


real anchor point X = anchor point X/Object width = 0.5
real anchor point y = anchor point Y/Object height = 0.8

提前谢谢你

enter image description here

import flash.events.Event;
import fl.motion.*;

run();

var frameID:uint;
var plistText:String;

function run()
{
plistText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n";
processFrame(null);
this.addEventListener(Event.ENTER_FRAME,processFrame);

}

function processFrame(e:Event)
{
if (this.currentFrameLabel != null) {
if (this.currentFrame != 1)
plistText += "</array>\n";
frameID = 0;
plistText += "<key>"+this.currentFrameLabel+"</key>\n<array>\n";
}
plistText+="<dict>\n";
plistText +="<key>FrameID</key>\n<string>"+frameID+"</string>\n"
frameID++;
for (var i:uint = 0; i < this.numChildren; i++)
{
var currentObject = this.getChildAt(i);
plistText += "<key>"+currentObject.name+"</key>\n"
plistText += "<dict>\n"
plistText += "<key>positionX</key>\n<string>"+currentObject.x+"</string>\n";
plistText += "<key>positionY</key>\n<string>"+currentObject.y+"</string>\n";
plistText += "<key>scaleX</key>\n<string>"+currentObject.scaleX+"</string>\n";
plistText += "<key>scaleY</key>\n<string>"+currentObject.scaleY+"</string>\n";
plistText += "<key>rotation</key>\n<string>"+currentObject.rotation+"</string>\n";
plistText += "<key>alpha</key>\n<string>"+currentObject.alpha+"</string>\n";
plistText += "<key>visible</key>\n<string>"+currentObject.visible+"</string>\n";
plistText += "</dict>\n"
}
plistText+="</dict>\n";
if (this.currentFrame == totalFrames)
{
plistText += "</array>\n</dict>\n</plist>";
trace(plistText)
removeEventListener(Event.ENTER_FRAME, processFrame);
this.stop();
}
}

最佳答案

您可以通过 getBounds()getRect() 调用获取对象的 anchor 。为此,您的 DisplayObject 应该可以访问舞台,否则 getBounds()getRect() 会返回虚假值(已测试)。实际上, anchor 对应于对象在其自身坐标空间中的 (0,0) 点,因此,为您的测试对象运行 test.getRect(test) 将返回 (-20,-18 ,40,90) - 注意 Y 坐标向下增长,而不是向上增长。然后,您得到该矩形的左上角,将其反转,瞧,对象相对于其尺寸的 anchor 。

function getAnchorPoint(o:DisplayObject):Point {
var onStage:Boolean;
var p:DisplayObject=o.parent;
onStage=(o.stage!=null);
if (!onStage) stage.addChild(o);
var res:Point=new Point();
var rect:Rectangle=o.getRect(o);
res.x=-1*rect.x;
res.y=-1*rect.y;
if (!onStage) {
stage.removeChild(o);
if (p) p.addChild(o);
}
return res;
}

关于flash - AS3 如何从显示对象获取定位点(枢轴、注册点)位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17537870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com