111,045
社区成员
发帖
与我相关
我的任务
分享
//主程序
namespace myBlockers
{
public class GameEngine : IFrameworkCallback,IDeviceCreation
{
//....
public static readonly string MediaPath = ConfigurationManager.AppSettings.Get("MediaPath");
//The information for the mesh that will display the level
private Mesh levelMesh = null;
private Texture[] levelTextures = null;
private void OnCreateDevice(object sender, DeviceEventArgs e)
{
SurfaceDescription desc = e.BackBufferDescription;
// Create the mesh for the level
ExtendedMaterial[] mtrls;
levelMesh = Mesh.FromFile(MediaPath + "level.x", MeshFlags.Managed, e.Device, out mtrls);
// Store the materials for later use, and create the textures
if ((mtrls != null) && (mtrls.Length > 0))
{
levelTextures = new Texture[mtrls.Length];
for (int i = 0; i < mtrls.Length; i++)
{
// Create the texture
levelTextures[i] = TextureLoader.FromFile(sampleFramework.Device, MediaPath +
mtrls[i].TextureFilename);
}
}
}
private void OnDestroyDevice(object sender, EventArgs e)
{
// Clean up the textures used for the mesh level
if ((levelTextures != null) && (levelTextures.Length > 0))
{
for (int i = 0; i < levelTextures.Length; i++)
{
levelTextures[i].Dispose();
}
// Clean up the mesh level itself
levelMesh.Dispose();
}
}
//...
}
}