我有多边形说(六角形,有6条直线)这个六边形从中心连接6点,形成6个三角形 我需要移动任何一点(因为移动三角形),其他点移动像这一点我的意思是如果左点移动提升其他点移动到左边等等
我想要的代码就像这个ptcP1.x和ptcP1.y我移动它的其他点移动的点取决于ptcP1运动注意,这个方程在方形中工作正常,放在Penta和hexa ..等这个有效的方程式,任何人都可以帮助我
function button1_triggeredHandler( event:Event ):void
{
mode="mode2";
//trace(list.selectedIndex);
if(list.selectedIndex==1)
{
DrawSqure.ptcP1.x = Math.random() + 50;
DrawSqure.ptcP1.y = Math.random() + 50;
DrawSqure.ptcP2.y = 50-DrawSqure.ptcP1.x;
DrawSqure.ptcP2.x = DrawSqure.ptcP1.y;
DrawSqure.ptcP3.x = 50-DrawSqure.ptcP1.y;
DrawSqure.ptcP3.y = DrawSqure.ptcP1.x;
DrawSqure.ptcP4.x = 50-DrawSqure.ptcP1.x;
DrawSqure.ptcP4.y = 50-DrawSqure.ptcP1.y;
}
答案 0 :(得分:0)
如评论中所述,将顶点/点存储到容器(Array
或Vector
)中,然后在移动时调整这些位置是最佳方法。以下是一个可行的示例:
//setup array or vector of vertices
var polygonVertices:Array = [DrawPolygon.ptcP1, DrawPolygon.ptcP2, DrawPolygon.ptcP3, DrawPolygon.ptcP4];
此方法将采用所有顶点并应用翻译:
//function for adjusting all the vertices based on the distance you pass
function moveShape( vertices:Array, dx:Number, dy:Number ) {
var i:int;
for ( ; i < vertices.length; i++ ) {
vertices[i].x += dx;
vertices[i].y += dy;
}
}
然后你只需要知道你的距离X&amp;你的形状已经移动,你可以拨打moveShape( polygonVertices, 100, 100 );
我插入100,100作为距离参数作为示例,但这应该为您提供所需的结果。