我正在尝试创建一个立方体循环并将ColorMaterial应用于曲面。 main actionscript类具有以下创建循环的方法。有一个名为Building的外部类文件负责形状和ColorMaterial。不幸的是,我似乎做错了什么。 Flash Builder未显示任何警告或错误。但是当我进行测试时,我得到的只是黑屏。
private function buildCity():void
{
var citySize:int = 1800;
var buildingSize:int = 100;
var roadSize:int = 50;
// Loop across in the x direction and again in the z direction
for(var cityX:int=citySize/2;cityX<citySize/2;cityX+=buildingSize+roadSize)
{
for(var cityZ:int=citySize/2;cityZ<citySize/2;cityZ+=buildingSize+roadSize)
{
// Create buildings
var building:Building = new Building();
// Position it
building.x = cityX;
building.z = cityZ;
// Add to the scene
view.scene.addChild(building);
}
}
}
负责形状和材质的Building类
package
{
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
public class Building extends Mesh
{
public function Building()
{
super(new CubeGeometry(50,100,50));
// Make a material
material = new ColorMaterial(Math.random()*0xFFFFFF);
// Offset the y position based on height
y = 50;
}
}
}
答案 0 :(得分:0)
检查循环参数。例如,在上面的代码中,您将cityX
设置为citySize / 2
,然后让它在cityX < citySize / 2
时进行迭代。
从一开始就cityX >= citySize / 2
,循环永远不会执行。
内循环也是如此。