Krypton in XNA with VB

Apr 10, 2012 at 6:20 PM


i use XNA with Visual Basic (2010 and XNA 3.1), so my question is, how can i use the krypton engine?

If i create a new reference, vb says its not corrrect..-.-

Is there any way to use Krypton in XNA and VB?

thy for help


ps: sry for my bad english^^

Apr 11, 2012 at 2:17 PM

Right click on your solution. -> add -> existing project -> browse to your krypton folder and add the csproj file :D

Done. :)
I have no Idea is this works at all with visual basic since it is written in C#
Apr 11, 2012 at 8:15 PM
Edited Apr 11, 2012 at 8:19 PM

This is a copy of an email I send to PaulKoch, figured someone could use it in the future.


There is no example but I'll send you some of my code (C#)

First of all add this to wherever you want to use krypton:
using Krypton;
using Krypton.Lights;
protected override void Draw(GameTime gameTime)
  // Matrix worldMatrix = Matrix.Identity;
  Matrix view = camera.ViewMatrix;

  // 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 = view;
  this.krypton.Bluriness = 3;

  #region influenced by krypton
  spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, null, camera.ViewMatrix);
  //some drawing code

  //you can draw here again with a new spritebatch which will be uninfluenced by krypton.
My camera.viewMatrix:
public Matrix ViewMatrix
get { return _viewMatrix; }

private void UpdateViewTransform()
Matrix proj = Matrix.CreateTranslation(new Vector3(_viewport.Width * 0.5f, _viewport.Height * 0.5f, 0)) *�
Matrix.CreateScale(new Vector3(1f, 1f, 1f));

_viewMatrix = Matrix.CreateRotationZ(_rotation) *
 Matrix.CreateScale(new Vector3(_zoom, _zoom, 1.0f)) *
Matrix.CreateTranslation(_position.X, _position.Y, 0.0f);
_viewMatrix = proj * _viewMatrix;
Now, you can give the kryptonengine to a void by doing this:
public void Update(int[] viewables, List<Lava> lavaList, List<Volcano> volcanoList, Texture2D sunSprite, Camera camera, KryptonEngine krypton)
and in that void you can create a shadowhull like this:
ShadowHull groundHull = ShadowHull.CreateRectangle(new Vector2(squareDimension, squareDimension));

groundHull.Position.X = spriteXPosition - (int)camera.cameraPosition.X + squareDimension / 2;
groundHull.Position.Y = spriteYPosition - (int)camera.cameraPosition.Y + squareDimension / 2;
groundHull.Visible = true;
groundHull.Opacity = 10f;


And also lights like this:
Light2D light = new Light2D();

light.Color = Color.Red;
light.IsOn = true;
light.X = x * squareDimension - (int)camera.cameraPosition.X + squareDimension / 2;
light.Y = y * squareDimension - (int)camera.cameraPosition.Y + squareDimension / 2;
light.Intensity = (float)random.Next(5, 7) / 10;
light.Range = 100;
light.Texture = sunSprite;


All the calculations are done by krypton, the only thing you have to do is set the viewmatrix and add a hull here and a light there :)
If you have a moving camera and dynamic hulls/lights, you will have to recreate the hulls and lights: Just a hint for you to save some power when the camera isn't moving:
if (camera.oldCameraPosition != camera.cameraPosition)

I hope you can bend this code to your will :) Any questions feel free to ask. :D
Good luck :)
Apr 12, 2012 at 6:33 AM

Sorry forgot to send some code with:

Do this:
using Krypton;
using Krypton.Lights;
Put this in your game class:
KryptonEngine krypton;
Then do this in your Public *gamename* { this.krypton = new KryptonEngine(this, "Effects/KryptonEffect"); }
Then put this in your initilization method: 
krypton.SpriteBatchCompatablityEnabled = true;
krypton.CullMode = CullMode.None;
krypton.AmbientColor = Color.Black;
Set those values to whatever you need. :)
Apr 20, 2012 at 12:04 AM


Is XNA with VB still causing you problems?

Nov 3, 2014 at 12:59 AM
I'm using VB just fine--Just had to add the .DLL as a library. Took a little bit of finding out, but it worked!