Showing posts with label XNA. Show all posts
Showing posts with label XNA. Show all posts

Wednesday, January 4, 2012

XNA : Ambient 2D Light

Hi,

To apply an ambient light in your game,a very simple way without using shaders.
To do this, simply edit color when Draw each sprite.


Add a the top of your game class :

float ambient = 1f;
Color ambientColor = Color.White;

 In the Update method :

 KeyboardState c = Keyboard.GetState();
 if (c.IsKeyDown(Keys.Space))
 {
    ambient -= 0.01f;
    if (ambient <= 0)
       ambient = 1f;
 }

And finally , to apply ambient on sprites :

Color drawColor = new Color(ambientColor.R / 255f * ambient, ambientColor.G / 255f * ambient, ambientColor.B / 255f * ambient);
spriteBatch.Begin();
spriteBatch.Draw(mySprite, new Vector2(0,0), drawColor);
spriteBatch.End();

As you see, it's very easy :) With this, you could simulate for example day cycle.

XNA : Little 2D Tile Lighting test

For a new project, i test have rewrite my light engine from C++ and 3D, to XNA in 2D.
 

Here a first preview :

I will explain my technique in few times

Tuesday, January 3, 2012

XNA : How to convert in code image to texture2D

Hi,

For a project, i have to load dynamic picture and use them into my game.

To do this i have simply create this little code :

public class ImageToTexture
{
     public static Texture2D loadPictureFromFile(GraphicsDevice graph, String file)
     {
          Stream ss = new FileStream(file, FileMode.Open);
          Texture2D load = Texture2D.FromStream(graph, ss);
          return load;
     }
}

ClimBro : WP7 on MarketPlace

Hi all,

The number of application of the marketplace (WP7) that I find completely boring is very important, so I had to try to publishing a game too.

So ClimBro was born in a 4 hours.

It's a platform game / jump with the aim of achieving the highest score by rebound on platforms and making combos.

Here a video of my express challenge game :