Light effects not drawn while My game is drawn

Apr 30, 2012 at 6:35 AM

Hello there, first of all, Very nice looking engine. I will definetly be donating if I get it working...

 

Anyways, on to my problem : Eventhough I put my game's drawing code between the // ----- DRAW STUFF HERE ----- //, the lighting effects of Krypton aren't visible. at this point I only putted a single spriteBatch.Draw() that draws the background (which is situated before this.krypton.Draw(gameTime);). When I comment that line and test it again,I can the see single lighting effect that I putted there for testing purposes ...

I feel like I am missing something obvious...

Thanks for the help in advance! 

 // Make sure we clear the backbuffer *after* Krypton is done pre-rendering
            this.GraphicsDevice.Clear(Color.White);
            // ----- DRAW STUFF HERE ----- //
            //background
            Head.level.background.Draw(spriteBatch);
            //runCount++;
            //if (runCount % 5 == 0)
            //    Head.level.background.DimColors();
            ////level objects
            //for (int i = 0; i < 3; i++)
            //{
            //    foreach (Object xObj in new List<Object>(Head.level.Objects))
            //    {
            //        if (xObj.DrawingPriority == i)
            //        {
            //            xObj.Draw(spriteBatch);
            //            if (xObj.IsCreature && xObj.Health * 100 / xObj.MaxHealth < 100)
            //            {
            //                spriteBatch.Draw(Graphics.expbarEmpty, new Rectangle(xObj.X + xObj.width / 2 - 25 - Head.BeeldX, xObj.Y - 30 - Head.BeeldY, 50, 10), Color.White);
            //                spriteBatch.Draw(Graphics.healthbar, new Rectangle(xObj.X + xObj.width / 2 - 25 - Head.BeeldX, xObj.Y - 30 - Head.BeeldY, (int)(50 * xObj.Health / xObj.MaxHealth), 10), Color.White);
            //            }
            //        }
            //    }
            //}
            ////animations
            //foreach (Particle xPtc in new List<Particle>(Head._particles))
            //{
            //    xPtc.Draw(spriteBatch);
            //}
            
            // By drawing here, you ensure that your scene is properly lit by krypton.
            // Drawing after KryptonEngine.Draw will cause you objects to be drawn on top of the lightmap (can be useful, fyi)
            // ----- DRAW STUFF HERE ----- //
            // Draw krypton (This can be omited if krypton is in the Component list. It will simply draw krypton when base.Draw is called
            this.krypton.Draw(gameTime);
May 1, 2012 at 6:53 PM

I'm sorry if I was a bit too confusing, Allow me to explain it a bit more clearer.....

Everything I draw with "spritebatch.draw()" goes infront of the lighting effects.

all my "spriteBatch.draw()" methods are standing above "this.krypton.Draw(gameTime);

May 4, 2012 at 8:38 PM
Edited May 4, 2012 at 8:44 PM

Heres the sourcecode, 

 

spriteBatch.Begin();

            List shadowableobjects = new List();
            krypton.Hulls.Clear();
            krypton.Lights.Clear();
            krypton.SpriteBatchCompatablityEnabled = true;

            foreach (Object xObj in Head.level.Objects)
            {               
                  ShadowHull xSh = ShadowHull.CreateRectangle(new Vector2(xObj.width, xObj.height));
                  xSh.Position = new Vector2(xObj.X-Head.BeeldX, xObj.Y-Head.BeeldY);
                  xSh.Scale = new Vector2(1, 1);
                  krypton.Hulls.Add(xSh);                 
            }

            krypton.Lights.Add(new Light2D() 
                {
                    Texture = mLightTexture,
                    Range = (float)(0.5 * 5 + 1),
                    Color = new Color(255,155,255),
                    Intensity = 100f,
                    Angle = MathHelper.TwoPi * 0.5f,
                    X = (float)(0.5 * 50 - 25),
                    Y = (float)(0.5 * 50 - 25),
                    Fov = MathHelper.PiOver2 * (float)(0.5 * 0.75 + 0.25) 
                });
            

            // Create a world view projection matrix to use with krypton
            Matrix world = Matrix.Identity;
            Matrix view = Matrix.CreateTranslation(new Vector3(0, 0, 0) * -1f);
            Matrix projection = Matrix.CreateOrthographic(this.mVerticalUnits * this.GraphicsDevice.Viewport.AspectRatio, this.mVerticalUnits, 0, 1);

            // Assign the matrix and pre-render the lightmap.
            // Make sure not to change the position of any lights or shadow hulls after this call, as it won't take effect till the next frame!
            this.krypton.Matrix = world * view * projection;
            this.krypton.Bluriness = 3;
            this.krypton.LightMapPrepare();

            // Make sure we clear the backbuffer *after* Krypton is done pre-rendering
            this.GraphicsDevice.Clear(Color.White);

            // ----- DRAW STUFF HERE ----- //
	    //my SpriteBatch drawing code here//
	 // By drawing here, you ensure that your scene is properly lit by krypton.            // Drawing after KryptonEngine.Draw will cause you objects to be drawn on top of the lightmap (can be useful, fyi)            // ----- DRAW STUFF HERE ----- //
            // Draw krypton (This can be omited if krypton is in the Component list. It will simply draw krypton when base.Draw is called            
         this.krypon.Draw(gameTime);

// My interface code//

      spriteBatch.End(); 

      base.Draw(gameTime);

May 10, 2012 at 9:57 AM

Shame

Developer
May 22, 2012 at 8:45 PM

Sorry for the delay in response. You happened to open this during our finals week, but luckily I just graduated from Uni so I've found more spare time :)

I'll construct a test based on what you've included, and this will hopefully shed some light on the situation.