Cannot seem to integrate with camera.

Mar 22, 2012 at 11:16 AM

I really need some help here. For the past 3 hours I've been trying to get the light to move according to camera. But I just can't seem to do it. I have been reading the topics here a lot and I haven't found anything that helped me.

When I followed the example I managed to see the light. But as soon as I moved the camera it disappeared extremely fast.

This is how I do my camera matrix:

Matrix cameraMatrix = Matrix.CreateTranslation(camera.X, camera.Y, 0);

//krypton.Matrix = ;
this.krypton.LightMapPrepare();
GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(0, null, null, null, null, null, cameraMatrix);
//Draw everything here
spriteBatch.End();

this.krypton.Draw(gameTime);
 

And this is how I move the camera:

if (playerLocation.X > 402.6 && playerLocation.X < 820)
{
     camera.X = (-playerLocation.X / 2 - playerBox.Width / 2) + (windowWidth / 4);
}

 

I have also added lights:

this.krypton = new KryptonEngine(this, "KryptonEffect");
this.krypton.Initialize();

Texture2D mLightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512);
light.Position = new Vector2(0, 0);
light.Range = 1;
light.Texture = mLightTexture;
light.IsOn = true;
light.Color = Color.White;
light.Intensity = 10f;
light.Fov = 40f;
krypton.Lights.Add(light);

I don't really much about how matrices works. So I would be glad if someone could modify this into something small and easy that works with krypton. I only need to move camera sideways and up/down, I don't need scale and rotation.

Coordinator
Mar 22, 2012 at 5:40 PM

Try this:

Matrix cameraMatrix = Matrix.CreateTranslation(camera.X, camera.Y, 0);

this.krypton.SpriteBatchCompatablityEnabled = true;
this.krypton.Matrix = cameraMatrix;
this.krypton.LightMapPrepare();
GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(0, null, null, null, null, null, cameraMatrix);
//Draw everything here
spriteBatch.End();

this.krypton.Draw(gameTime);

Mar 22, 2012 at 5:56 PM

For some reason the lights disappear totally when I do it like that. Could it have something to do with the fact that I changed from int32 to int16 in the renderhelper file? I did that to be able to use the game in reach profile.

Mar 22, 2012 at 6:07 PM

Never mind. That should not be a problem. I tested the demo with both Int32 and Int16, both worked.

Mar 22, 2012 at 7:27 PM

The problem still persists though. I have tried the latest build also. The same happens there; when I use a matrix that is set to 0,0,0 I get the light in the middle of the screen, when I set SpriteBatchCompabilityEnabled=true or use the camera matrix as kryptons matrix the screen goes black.

Coordinator
Mar 22, 2012 at 7:29 PM

You'll need to set the cull mode to None, (or the opposite direction of what you've currently got it set to) while drawing krypton.

Mar 22, 2012 at 8:15 PM

Yay! I managed to get the lights and shadows working! Thanks! :D. Only one slight problem. When I read my maps (with tiledlib) I add shadow hulls at the same time. This is working good, but when I start my game I see tiny hulls at the top left corner of the map. It's like I am seeing a miniatures of my map. How do I fix this the right way?

Mar 24, 2012 at 8:09 AM

sounds like you might need to mess with the zoom / scale of your transform.