0

我正在尝试创建一个立方体循环并将 ColorMaterial 应用于表面。主要的 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);
            }
        }
    }       

负责形状和材料的建筑类

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;
    }
}
}
4

1 回答 1

0

检查您的循环参数。例如,在上面的代码中,您设置cityXcitySize / 2,然后让它迭代 while cityX < citySize / 2

因为cityX >= citySize / 2从一开始,循环就永远不会执行。

内循环也是如此。

于 2014-01-13T16:10:52.667 回答