0
\$\begingroup\$

i have some models that i only draw at a certain moment in the game (after some seconds since the game has started). The problem is that in that first second when i start to draw the models, i see a flicker (in the sence that everything besides those models, dissapears, the background gets purple). The flicker only lasts for that frame, and then everything seems to run the way it should.

UPDATE I see now that regardless of the moment i draw the models, the first frame has always the flickering aspect

What could this be about? i'll share my draw method:

int temp = 0;
foreach (MeshObject meshObj in ShapeList)
{
    foreach (BasicEffect effect in meshObj.mesh.Effects)
    {
        #region color elements

        int i = int.Parse(meshObj.mesh.Name.ElementAt(1) + "");
        int j = int.Parse(meshObj.mesh.Name.ElementAt(2) + "");
        int getShapeColor = shapeColorList.ElementAt(i * 4 + j);
        if (getShapeColor == (int)Constants.shapeColor.yellow)
            effect.DiffuseColor = yellow;
        else if (getShapeColor == (int)Constants.shapeColor.red)
            effect.DiffuseColor = red;
        else if (getShapeColor == (int)Constants.shapeColor.green)
            effect.DiffuseColor = green;
        else if (getShapeColor == (int)Constants.shapeColor.blue)
            effect.DiffuseColor = blue;

        #endregion

        #region lighting

        effect.LightingEnabled = true;
        effect.AmbientLightColor = new Vector3(0.25f, 0.25f, 0.25f);

        effect.DirectionalLight0.Enabled = true;
        effect.DirectionalLight0.Direction = new Vector3(-0.3f, -0.3f, -0.9f);
        effect.DirectionalLight0.SpecularColor = new Vector3(.7f, .7f, .7f);

        Vector3 v = Vector3.Normalize(new Vector3(-100, 0, -100));
        effect.DirectionalLight1.Enabled = true;
        effect.DirectionalLight1.Direction = v;
        effect.DirectionalLight1.SpecularColor = new Vector3(0.6f, 0.6f, .6f);

        #endregion

        effect.Projection = camera.projectionMatrix;
        effect.View = camera.viewMatrix;
        if (meshObj.isSetInPlace == true)
        {
            effect.World = transforms[meshObj.mesh.ParentBone.Index] * gameobject.orientation; // draw in original cube-placed position
            meshObj.mesh.Draw();
        }
        else
        {
            effect.World = meshObj.Orientation; // draw inSetInPlace position
            meshObj.mesh.Draw();
        }
    }
    temp++;
}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ For starters, I don't think you should be doing meshObj.mesh.Draw() inside the inner foreach loop, because that way you'll be potentially drawing the mesh several times per frame. Move that call to the bottom of the outer foreach instead. \$\endgroup\$ Mar 1, 2012 at 16:12
  • \$\begingroup\$ thanks! good point but it still doesn't solve my problem. \$\endgroup\$
    – Alex
    Mar 1, 2012 at 16:19
  • \$\begingroup\$ Yeah, I didn't think it would. I think the purple background usually shows when you're not clearing the graphics device at the top of your Draw method. Are you calling GraphicsDevice.Clear() properly? \$\endgroup\$ Mar 1, 2012 at 16:24
  • \$\begingroup\$ yes, i am calling .Clear() on every draw \$\endgroup\$
    – Alex
    Mar 1, 2012 at 16:48

1 Answer 1

1
\$\begingroup\$

found out what the problem was. the app was SL/XNA and it was redering the purple flicker because of the rendering of the SL UI. Still, don't know how to overcome this if you want to have objects render behind the SL s

SL draw method

 spriteBatch.Begin();
        elementRenderer.Render();
        spriteBatch.Draw(elementRenderer.Texture, Vector2.Zero, Color.White);

        spriteBatch.End();
\$\endgroup\$
2
  • 3
    \$\begingroup\$ The documentation says that you should call elementRenderer.Render(); before SpriteBatch.Begin() not after. See if that makes any difference. Also I think you should have added this as an edit to your question, not as an answer, since it didn't really solve your problem, only identified it. \$\endgroup\$ Mar 2, 2012 at 13:26
  • \$\begingroup\$ didn't fix the problem (moving .Render(); outside of Begin - End). Maybe this is a SLXNA bug \$\endgroup\$
    – Alex
    Mar 5, 2012 at 10:17

You must log in to answer this question.

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