Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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++;
}
share|improve this question
1  
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. –  David Gouveia Mar 1 '12 at 16:12
    
thanks! good point but it still doesn't solve my problem. –  Badescu Alexandru Mar 1 '12 at 16:19
    
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? –  David Gouveia Mar 1 '12 at 16:24
    
yes, i am calling .Clear() on every draw –  Badescu Alexandru Mar 1 '12 at 16:48
add comment

1 Answer 1

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();
share|improve this answer
3  
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. –  David Gouveia Mar 2 '12 at 13:26
    
didn't fix the problem (moving .Render(); outside of Begin - End). Maybe this is a SLXNA bug –  Badescu Alexandru Mar 5 '12 at 10:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.