Non cominciamo a parlare difficile.
eventhandler?
La gestione della tastiera è addebitata al metodo KeyControl() in Updatr() nel file My.cs e richiama il metodo Ctrls della struttura Discovery (l'astronave) nel file Discovery.cs.
Ecco le parti salienti dei due files:
My.cs:
codice:
namespace Progetto_Albireo
{
public class My : Microsoft.Xna.Framework.Game
{
//Generals
public static GraphicsDeviceManager Graphicsdevicemanager;
#if WIDE
public static int RisX, RisY;
#else
public static int RisX = 1350;
public static int RisY = 650;
#endif
RenderTarget2D renderTarget;
Texture2D shadowMap;
MemoryStream stream = new MemoryStream();
..........
//Discovery
public static Discovery Discovery =
new Discovery(new Vector3(0f, 0f, 30000f), //Position
-Vector3.UnitZ, //Go
10f, //Speed
-Vector3.UnitZ, //To
Vector3.Up); //Up
..........
public static bool PhotoMode = false;
..........
public void KeyControl()
{
KeyState = Keyboard.GetState();
if ((KeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) & (OldState != KeyState))
this.Exit();
if (OldState != KeyState)
Discovery.Ctrls(KeyState);
OldState = KeyState;
}
public My()
{
Graphicsdevicemanager = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
..........
shadowMap = new Texture2D(GraphicsDevice, RisX, RisY);
PresentationParameters pp = GraphicsDevice.PresentationParameters;
renderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight,
false, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24);
base.Initialize();
}
protected override void LoadContent()
{
..........
}
protected override void Update(GameTime gametime)
{
..........
KeyControl();
//DISCOVERY
Discovery.Move();
}
protected override void Draw(GameTime gametime)
{
if (PhotoMode)
GraphicsDevice.SetRenderTarget(renderTarget);
..........
if (PhotoMode)
{
GraphicsDevice.SetRenderTarget(null);
shadowMap = (Texture2D)renderTarget;
shadowMap.SaveAsJpeg(stream, RisX, RisY);//o SaveAsPng()
System.Drawing.Bitmap b = new System.Drawing.Bitmap(stream);
b.Save(@"C:\frame.bmp");
PhotoMode = false;
}
}
}
}
Discovery.cs:
codice:
namespace Progetto_Albireo
{
public struct Discovery
{
//principali
public Vector3 Position;
public Vector3 Go;
public float Speed;
public Vector3 To;
public Vector3 Up;
..........
public Discovery(Vector3 P, Vector3 G, float S, Vector3 T, Vector3 U)
{
..........
}
..........
public void Ctrls(KeyboardState KeyState)
{
..........
if (KeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
{
if (My.PhotoMode)
My.PhotoMode = false;
else
My.PhotoMode = true;
}
..........