Krypton Light position in terms of screen position

Jul 23, 2012 at 7:57 PM

Hey guys,

 

So I noticed in general, that spawning a light at (0,0) with Krypton causes the light to appear in, pretty much, the centre of the game screen. Is there any way to change this so a Krypton light's "starting point" at [0,0] would spawn at the top left of the screen, and thus follow the standard screen co-ordinates for position?

 

I ask because currently I'm busy working on my game where my spawn point is [512,512]. With hard code, the closest I've got to the light being "central" to this point is the vector position [12,-20], which makes no sense and is impossible to craft, mathematically, if I want the light to move with the camera (the position [480,512] maps roughly to [10,-20]).

 

So, is there any way to "normalise" the krypton lights to use standard screen co-ordinates?

 

Thanks guys.

Aug 2, 2012 at 6:00 PM
Edited Aug 2, 2012 at 6:11 PM

Honestly I've forgotten the parameter names (brain fart moment) but there are 2 parameters storing the width and height of your screen respectively. Minus half the width from your light and it should spawn dead center on the left edge, minus half the height and it will be moved to the top. Once you've done that you should then be able to map it to whatever location you wish

 

 

EDIT:

Ok somewhere in game1.cs assuming the default template names there will be something like this:

public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

graphics.PreferredBackBufferWidth

graphics.PrefferedBackBufferHeight

Half them. There you go

Aug 2, 2012 at 6:36 PM

Awesome, so assume your light is defined as such:

 

                light = new Light2D()
                {
                    Texture = texture,
                    Range = (float)(10),
                    Color = new Color(r, g, b),
                    Intensity = 1f,
                    Angle = MathHelper.TwoPi * (float)mRandom.NextDouble(),
                    X = 0,
                    Y = 0,
                };

Note the X and Y 0 "spawnpoints", would the X and Y change to X = -(graphics.PrefferedBackBufferWidth/2) and Y = -(graphics.PrefferedBackBufferHeight/2)? Because that somehow just kills everything. To be more specific, I'm not sure what you mean by minusing width/height from my light - am I applying these to X and Y values or is there an actual Width/Height property that I need to adjust?

Aug 4, 2012 at 3:33 PM

A light position of 0,0 makes it centered on screen ok.

X = -(graphics.PreferredBackBufferWidth / 2)
Y = -(graphics.PreferredBackBufferheight / 2)

That should move the light to the top left corner.

Then X = X+[your new location] should move the light to [your new location] number of pixels from the left.