I'm a sophomore CS student at Oregon State and am still new to XNA and programming. I'm creating a 2d top down game which uses a camera to follow the player. I only ran into trouble when I tried implementing Krypton, a free lighting engine that is apparently quite popular. Many people on their message boards have had similar issues to mine but I can't translate their findings to my code and have it work. Any lights I create through the engine stay still relative to the screen, while the scenery it should be attached to moves behind it. I can't seem to feed Krypton the right view matrix for it to work properly. Any help I could get from here would be great, the message boards at Krypton aren't too lively, so i figured i'd try this out.
This code snippet right here is in the draw method, taken from the testbed example of the camera. This is the code I need to mess with for it to have the lights "stick" to my actual game world.
// Create a world view projection matrix to use with krypton
Matrix world = Matrix.Identity;
//Matrix view = mainCamera.get_transformation(graphics.GraphicsDevice);
Matrix view = Matrix.CreateTranslation(new Vector3((float)0, (float)0, 0));
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.SpriteBatchCompatablityEnabled = true;
//this.krypton.Matrix = testMatrix;
this.krypton.Matrix = world * view * projection;
this.krypton.Bluriness = 4;
this.krypton.LightMapPrepare();
this.krypton.Draw(gameTime);
this.DebugDraw();
But I also utilize a camera:
//Draw method
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
mainCamera.get_transformation(graphics.GraphicsDevice));
Camera.cs
public class Camera
{
protected float cameraZoomValue; // Camera Zoom
public Matrix cameraTransformValue; // Matrix Transform
public Vector2 cameraPosition; // Camera Position
protected float cameraRotationValue; // Camera Rotation
public Camera()
{
cameraZoomValue = 1.0f;
cameraRotationValue = 0.0f;
cameraPosition = Vector2.Zero;
}
public float Zoom
{
get { return cameraZoomValue; }
set { cameraZoomValue = value; if (cameraZoomValue < 0.1f) cameraZoomValue = 0.1f; } // Negative zoom will flip image
}
public float Rotation
{
get { return cameraRotationValue; }
set { cameraRotationValue = value; }
}
// Auxiliary function to move the camera
public void Move(Vector2 amount)
{
cameraPosition += amount;
}
// Get set position
public Vector2 Position
{
get { return cameraPosition; }
set { cameraPosition = value; }
}
public Matrix get_transformation(GraphicsDevice graphicsDevice)
{
cameraTransformValue =
Matrix.CreateTranslation(new Vector3(-cameraPosition.X, -cameraPosition.Y, 0)) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
return cameraTransformValue;
}
}
I am still very new to coding forums and asking for help, so if I need to provide any more code let me know!

New Topic/Question
Reply


MultiQuote



|