我正在制作受卡坦定居者启发的游戏。( www.facebook.com/Expanze ) 我正在优化我的代码,它呈现数百个相同模型的实例。
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.Alpha = 1.0f;
effect.LightingEnabled = true;
effect.DirectionalLight0.Direction = GameState.LightDirection;
effect.DirectionalLight0.DiffuseColor = GameState.LightDiffusionColor;
effect.DirectionalLight0.SpecularColor = GameState.LightSpecularColor;
effect.DirectionalLight0.Enabled = true;
effect.View = GameState.view;
effect.Projection = GameState.projection;
for (int loop1 = 0; loop1 < validItems; loop1++)
{
if (instance[loop1].Visible)
{
instance[loop1].UpdateEffect(effect, meshNumber);
effect.World = transforms[mesh.ParentBone.Index] * instance[loop1].World;
mesh.Draw();
if(loop1 > 4)
break;
}
}
}
meshNumber++;
}
在 :
instance[loop1].UpdateEffect(effect, meshNumber);
我改变环境颜色:effect.AmbientLightColor = playerAmbientLightColor;
我的问题是更改颜色会影响应该已经绘制的早期实例的颜色。
两张图片,一张带有 if(loop1 > 4) break,第二张没有这两行:http: //i.imgur.com/DxSKA.jpg