Flash AS2绘制山丘曲线-随机工作
我有一个数组,其中包含用于绘制多个山丘的点。当我只画直线时,效果很好,但这是不自然的,所以我想使山的顶部/底部弯曲Flash AS2绘制山丘曲线-随机工作,flash,actionscript,drawing,actionscript-2,Flash,Actionscript,Drawing,Actionscript 2,我有一个数组,其中包含用于绘制多个山丘的点。当我只画直线时,效果很好,但这是不自然的,所以我想使山的顶部/底部弯曲 for(i = 0; i < rPoints.length - 1; i++){ gamebg.lineStyle(1,0x000000,100); gamebg.moveTo(rPoints[i][0] + 45, rPoints[i][1]); //Doesn't directly move to a point so there is empty spa
for(i = 0; i < rPoints.length - 1; i++){
gamebg.lineStyle(1,0x000000,100);
gamebg.moveTo(rPoints[i][0] + 45, rPoints[i][1]); //Doesn't directly move to a point so there is empty space for the curved parts.
if(rPoints[i+1][1] > rPoints[i][1]){ //Determines if it is the top part of a hill or a bottom part, compares y
gamebg.lineTo(rPoints[i+1][0], rPoints[i+1][1]);
gamebg.moveTo(rPoints[i+1][0], rPoints[i+1][1]);
//I didn't add a curveTo here because I only wanted to test it on one so I can make changes easier
} else {
gamebg.lineTo(rPoints[i+1][0], rPoints[i+1][1]);
gamebg.moveTo(rPoints[i+1][0], rPoints[i+1][1]);
gamebg.curveTo(rPoints[i+1][0]+22, rPoints[i+1][1]-25, rPoints[i+1][1]+45, rPoints[i+1][1]);
}
}
for(i=0;irPoints[i][1]){//确定它是山丘的顶部还是底部,则比较y
gamebg.lineTo(rPoints[i+1][0],rPoints[i+1][1]);
gamebg.moveTo(rPoints[i+1][0],rPoints[i+1][1]);
//我没有在这里添加curveTo,因为我只想在其中一个上测试它,这样我可以更轻松地进行更改
}否则{
gamebg.lineTo(rPoints[i+1][0],rPoints[i+1][1]);
gamebg.moveTo(rPoints[i+1][0],rPoints[i+1][1]);
gamebg.curveTo(rpoint[i+1][0]+22,rpoint[i+1][1]-25,rpoint[i+1][1]+45,rpoint[i+1][1]);
}
}
当我运行代码时,有时它似乎可以工作
当它起作用时,它只对第一个起作用。
谢谢 根据包含点的数组的顺序来确定山的各个部分要容易得多。在这种情况下,必须按3而不是1进行迭代。我测试了下面的代码,效果很好。 *尼古拉斯
/*
* ActionScript 2
*
* Drawing some Hills :-)
*
* The following Loop draws Hills using an Array containing
* a multiple of 3 Points
*
* p5
* p2 /\
* /\ / \
* / \ / \
* p1 p3 p4 p6
*
*/
var rPoints = [
// First Hill
[50,200],
[100,10],
[150,200],
// Second Hill
[100,200],
[150,80],
[200,200],
// Will not be drawn
[500,200]
];
for(i = 0; i <= rPoints.length-3; i+=3){
gamebg.lineStyle(1,0x000000,100);
// Move to the 1st Point
gamebg.moveTo(rPoints[i][0], rPoints[i][1]);
// Curve to 2nd Point (For a smooth curve the Control Point should be in the Top Left Corner)
gamebg.curveTo(rPoints[i][0], rPoints[i+1][1], rPoints[i+1][0], rPoints[i+1][1]);
// Curve to 3rd Point (For a smooth curve the Control Point should be in the Top Right Corner)
gamebg.curveTo(rPoints[i+2][0], rPoints[i+1][1], rPoints[i+2][0], rPoints[i+2][1]);
// Close the shape (If you want to)
gamebg.lineTo(rPoints[i][0], rPoints[i][1]);
}
/*
*动作脚本2
*
*画一些山:-)
*
*下面的循环使用包含
*三点的倍数
*
*p5
*p2/\
* /\ / \
* / \ / \
*p1 p3 p4 p6
*
*/
变量rPoints=[
//第一山
[50,200],
[100,10],
[150,200],
//第二座山
[100,200],
[150,80],
[200,200],
//将不会被抽取
[500,200]
];
对于(i=0;i