1
\$\begingroup\$

I want to change color of individual model in my game. But when I use

effect.DiffuseColor = newColor

then all of models which were loaded from same model file change color too.

How can I do ?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

you are changing the Diffusecolor in the same effect.

there is no easy way to clone a model

so the answer is before draw set the color properly for each model

// Draw method
foreach (ModelMesh mesh in m.Meshes)
{
    foreach (BasicEffect effect in mesh.Effects)
    {
       effect.DiffuseColor = newColor;   
    }
    mesh.Draw();    
}
\$\endgroup\$
1
  • \$\begingroup\$ In addition to this I would be setting the Diffuse color from an the mesh object. This way you can have a default color being applied to the effect if no Diffuse color is needed. \$\endgroup\$
    – ZeunO8
    Commented Nov 8, 2011 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .