XNA 3.1 转换到 XNA4.0 的备忘录
XNA 3.1 转换到 XNA4.0 的备忘录xna3.1与4.0的区别不小,但也不是很大,在转换一些项目时候下面的tip能给些帮助。原文地址是:http://blogs.msdn.com/b/shawnhar/archive/2011/01/04/xna-3-1-to-4-0-cheat-sheet.aspx?utm_source=twitterfeed&utm_medium=twitter
遇到如下问题,该备忘录将解决的问题: The name ‘SpriteBlendMode‘ does not exist in the current context The name ‘SaveStateMode‘ does not exist in the current context ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice‘ does not contain a definition for ‘RenderState‘… ‘Microsoft.Xna.Framework.Graphics.Effect‘ does not contain a definition for ‘Begin‘ … ‘Microsoft.Xna.Framework.Graphics.Effect‘ does not contain a definition for ‘End‘.. ‘Microsoft.Xna.Framework.Graphics.Effect‘ does not contain a definition for ‘CommitChanges‘ … ‘Microsoft.Xna.Framework.Graphics.EffectPass‘ does not contain a definition for ‘Begin‘ … ‘Microsoft.Xna.Framework.Graphics.EffectPass‘ does not contain a definition for ‘End‘ …. No overload for method ‘Clone‘ takes 1 arguments The name ‘ShaderProfile‘ does not exist in the current context ‘Microsoft.Xna.Framework.GameTime‘ does not contain a definition for ‘TotalRealTime‘ … ‘Microsoft.Xna.Framework.Color‘ does not contain a definition for ‘TransparentBlack‘ … The type or namespace name ‘ResolveTexture2D‘ could not be found … ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice‘ does not contain a definition for ‘ResolveBackBuffer‘… The type or namespace name ‘DepthStencilBuffer‘ could not be found … ‘Microsoft.Xna.Framework.Graphics.RenderTarget2D‘ does not contain a constructor that takes 5 arguments … ‘Microsoft.Xna.Framework.Graphics.RenderTarget2D‘ does not contain a definition for ‘GetTexture‘ … ‘Microsoft.Xna.Framework.Graphics.PresentationParameters‘ does not contain a definition for ‘MultiSampleType‘ … ‘Microsoft.Xna.Framework.Graphics.PresentationParameters‘ does not contain a definition for ‘MultiSampleQuality‘ … The best overloaded method match for ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice.SetRenderTarget… ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice‘ does not contain a definition for ‘VertexDeclaration‘ ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice‘ does not contain a definition for ‘Vertices‘ ‘Microsoft.Xna.Framework.Graphics.VertexPositionTexture‘ does not contain a definition for ‘SizeInBytes‘ ‘Microsoft.Xna.Framework.Graphics.VertexPositionTexture‘ does not contain a definition for ‘VertexElements‘ ‘Microsoft.Xna.Framework.Graphics.ModelMesh‘ does not contain a definition for ‘IndexBuffer‘ ‘Microsoft.Xna.Framework.Graphics.ModelMesh‘ does not contain a definition for ‘VertexBuffer‘ ‘Microsoft.Xna.Framework.Graphics.ModelMeshPart‘ does not contain a definition for ‘BaseVertex‘ ‘Microsoft.Xna.Framework.Graphics.ModelMeshPart‘ does not contain a definition for ‘StreamOffset‘ ‘Microsoft.Xna.Framework.Graphics.ModelMeshPart‘ does not contain a definition for ‘VertexStride‘ ‘Microsoft.Xna.Framework.Storage.StorageContainer‘ does not contain a definition for ‘TitleLocation‘ ‘Microsoft.Xna.Framework.Storage.StorageContainer‘ does not contain a definition for ‘Path‘ ‘Microsoft.Xna.Framework.Storage.StorageDevice‘ does not contain a definition for ‘OpenContainer‘ ‘Microsoft.Xna.Framework.GamerServices.Guide‘ does not contain a definition for ‘BeginShowStorageDeviceSelector‘ ‘Microsoft.Xna.Framework.GamerServices.Guide‘ does not contain a definition for ‘EndShowStorageDeviceSelector‘ syntax error: unexpected token ‘VertexShader‘ syntax error: unexpected token ‘PixelShader‘ error X3539: ps_1_x is no longer supported PS:其他问题,如xna模型画出边界,看起来透明或者丢失顶点以及看起来不对劲。 ---------------------------------------------------------------------------------------- XNA 3.1 转为 XNA4.0 的例子: SpriteBlendMode, SaveStateMode 2 | sprite.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState); |
4 | sprite.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); |
1 | spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None); |
1 | spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); |
4 | sprite.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState); |
6 | sprite.Begin(SpriteSortMode.Immediate, BlendState.Opaque); |
1 | spriteBatch.Begin(SpriteBlendMode.None); |
2 | Viewport viewport = GraphicsDevice.Viewport; |
3 | spriteBatch.Draw(background, new Rectangle(0, 0, viewport.Width, viewport.Height), Color.White); |
1 | spriteBatch.Begin(0, BlendState.Opaque); |
2 | spriteBatch.Draw(background, GraphicsDevice.Viewport.Bounds, Color.White); |
RenderState 01 | GraphicsDevice.RenderState.AlphaBlendEnable = true ; |
02 | GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; |
03 | GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; |
04 | GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true ; |
05 | GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add; |
06 | GraphicsDevice.RenderState.AlphaSourceBlend = Blend.One; |
07 | GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.One; |
08 | GraphicsDevice.RenderState.DepthBufferWriteEnable = false ; |
1 | GraphicsDevice.BlendState = BlendState.AlphaBlend; |
2 | GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; |
1 | GraphicsDevice.RenderState.AlphaBlendEnable = false ; |
2 | GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false ; |
3 | GraphicsDevice.RenderState.DepthBufferWriteEnable = true ; |
1 | GraphicsDevice.BlendState = BlendState.Additive; |
2 | GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 | GraphicsDevice.RenderState.DepthBufferEnable = true ; |
1 | GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 | GraphicsDevice.RenderState.DepthBufferWriteEnable = false ; |
2 | GraphicsDevice.RenderState.DepthBufferEnable = false ; |
01 | GraphicsDevice.DepthStencilState = DepthStencilState.None; |
05 | GraphicsDevice.RenderState.DepthBufferWriteEnable = false ; |
06 | GraphicsDevice.RenderState.AlphaBlendEnable = true ; |
07 | GraphicsDevice.RenderState.SourceBlend = Blend.One; |
08 | GraphicsDevice.RenderState.DestinationBlend = Blend.One; |
11 | GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; |
12 | GraphicsDevice.BlendState = BlendState.AlphaBlend; |
1 | GraphicsDevice.RenderState.DepthBufferWriteEnable = true ; |
2 | GraphicsDevice.RenderState.AlphaBlendEnable = false ; |
3 | GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false ; |
1 | GraphicsDevice.BlendState = BlendState.Opaque; |
2 | GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 | GraphicsDevice.RenderState.DepthBufferEnable = false ; |
2 | GraphicsDevice.RenderState.DepthBufferWriteEnable = false ; |
3 | GraphicsDevice.RenderState.AlphaBlendEnable = true ; |
4 | GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; |
5 | GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; |
1 | GraphicsDevice.DepthStencilState = DepthStencilState.None; |
2 | GraphicsDevice.BlendState = BlendState.AlphaBlend; |
1 | GraphicsDevice.RenderState.AlphaBlendEnable = false ; |
2 | GraphicsDevice.RenderState.AlphaTestEnable = false ; |
3 | GraphicsDevice.RenderState.DepthBufferEnable = true ; |
1 | GraphicsDevice.BlendState = BlendState.Opaque; |
2 | GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
1 | GraphicsDevice.RenderState.AlphaBlendEnable = true ; |
2 | GraphicsDevice.RenderState.SourceBlend = Blend.One; |
3 | GraphicsDevice.RenderState.DestinationBlend = Blend.One; |
1 | GraphicsDevice.BlendState = BlendState.Additive; |
1 | GraphicsDevice.RenderState.DestinationBlend = Blend.One; |
1 | GraphicsDevice.BlendState = BlendState.Additive; |
1 | GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; |
1 | GraphicsDevice.BlendState = BlendState.AlphaBlend; |
4 | GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; |
6 | GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; |
01 | GraphicsDevice.RenderState.DepthBufferEnable = false ; |
02 | GraphicsDevice.RenderState.DepthBufferWriteEnable = false ; |
03 | GraphicsDevice.RenderState.AlphaBlendEnable = true ; |
04 | GraphicsDevice.RenderState.SourceBlend = Blend.One; |
05 | GraphicsDevice.RenderState.DestinationBlend = Blend.One; |
06 | GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true ; |
07 | GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add; |
08 | GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.Zero; |
09 | GraphicsDevice.RenderState.AlphaSourceBlend = Blend.Zero; |
1 | GraphicsDevice.RenderState.DepthBufferEnable = true ; |
2 | GraphicsDevice.RenderState.DepthBufferWriteEnable = true ; |
3 | GraphicsDevice.RenderState.AlphaBlendEnable = false ; |
4 | GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false ; |
1 | DepthStencilState ds = GraphicsDevice.DepthStencilState; |
2 | BlendState bs = GraphicsDevice.BlendState; |
1 | GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; |
2 | GraphicsDevice.BlendState = BlendState.AlphaBlend; |
1 | GraphicsDevice.DepthStencilState = ds; |
2 | GraphicsDevice.BlendState = bs; |
Effect, EffectPass, Begin(), End(), CommitChanges(), Clone() 02 | blurEffect.CommitChanges(); |
03 | blurEffect.Begin(SaveStateMode.SaveState); |
04 | blurEffect.CurrentTechnique.Passes[0].Begin(); |
05 | GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); |
06 | blurEffect.CurrentTechnique.Passes[0].End(); |
09 | blurEffect.CurrentTechnique.Passes[0].Apply(); |
10 | GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); |
1 | effect.Begin(SaveStateMode.SaveState); |
2 | effect.CurrentTechnique.Passes[0].Begin(); |
1 | effect.CurrentTechnique.Passes[0].Apply(); |
1 | effect.CurrentTechnique.Passes[0].End(); |
1 | Effect newEffect = replacementEffect.Clone(replacementEffect.GraphicsDevice); |
1 | Effect newEffect = replacementEffect.Clone(); |
01 | postprocessEffect.CurrentTechnique = postprocessEffect.Techniques[effectTechniqueName]; |
04 | spriteBatch.Begin(SpriteBlendMode.None,SpriteSortMode.Immediate, SaveStateMode.None); |
06 | postprocessEffect.Begin(); |
07 | postprocessEffect.CurrentTechnique.Passes[0].Begin(); |
09 | spriteBatch.Draw(sceneRenderTarget.GetTexture(), Vector2.Zero, Color.White); |
12 | postprocessEffect.CurrentTechnique.Passes[0].End(); |
13 | postprocessEffect.End(); |
1 | postprocessEffect.CurrentTechnique = postprocessEffect.Techniques[effectTechniqueName]; |
1 | spriteBatch.Begin(0, BlendState.Opaque, null , null , null , postprocessEffect); |
2 | spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White); |
ShaderProfile, TotalRealTime, TransparentBlack 2 | graphics.MinimumPixelShaderProfile = ShaderProfile.PS_3_0; |
3 | graphics.MinimumVertexShaderProfile = ShaderProfile.VS_3_0; |
2 | float myTime = ( float )gameTime.TotalRealTime.TotalSeconds * 0.2f; |
4 | float myTime = ( float )gameTime.TotalGameTime.TotalSeconds * 0.2f; |
7 | GraphicsDevice.Clear(Color.TransparentBlack); |
9 | GraphicsDevice.Clear(Color.Transparent); |
ResolveTexture2D, ResolveBackBuffer, RenderTarget2D, GetTexture, DepthStencilBuffer, PresentationParameters, MultiSampleType, MultiSampleQuality, SetRenderTarget 02 | ResolveTexture2D sceneMap; |
04 | RenderTarget2D sceneMap; |
08 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
11 | sceneMap = new ResolveTexture2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, pp.BackBufferFormat); |
14 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
17 | sceneMap = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false , pp.BackBufferFormat, |
18 | pp.DepthStencilFormat); |
21 | sceneMap = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false , pp.BackBufferFormat, |
22 | pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); |
25 | GraphicsDevice.ResolveBackBuffer(sceneMap); |
27 | GraphicsDevice.SetRenderTarget(sceneMap); |
30 | int width = GraphicsDevice.Viewport.Width; |
31 | int height = GraphicsDevice.Viewport.Height; |
1 | myRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, 1, SurfaceFormat.Color); |
3 | int width = GraphicsDevice.Viewport.Width; |
4 | int height = GraphicsDevice.Viewport.Height; |
1 | myRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, true , SurfaceFormat.Color, DepthFormat.Depth24); |
4 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
1 | sceneRenderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, |
2 | pp.BackBufferFormat, pp.MultiSampleType, pp.MultiSampleQuality); |
4 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
1 | sceneRenderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false , |
2 | pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, |
3 | RenderTargetUsage.DiscardContents); |
6 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
1 | drawBuffer = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, |
2 | SurfaceFormat.Color, pp.MultiSampleType, pp.MultiSampleQuality); |
4 | drawDepthBuffer = new DepthStencilBuffer(GraphicsDevice, pp.AutoDepthStencilFormat, |
5 | pp.MultiSampleType, pp.MultiSampleQuality); |
7 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
1 | drawBuffer = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true , |
2 | SurfaceFormat.Color,DepthFormat.Depth24Stencil8, |
3 | pp.MultiSampleCount, RenderTargetUsage.DiscardContents); |
2 | spriteBatch.Draw(myRenderTarget.GetTexture(), Vector2.Zero, Color.White); |
4 | spriteBatch.Draw(myRenderTarget, Vector2.Zero, Color.White); |
02 | Texture2D myTexture = myRenderTarget.GetTexture(); |
04 | Texture2D myTexture = myRenderTarget; |
07 | GraphicsDevice.SetRenderTarget(0, myRenderTarget); |
09 | GraphicsDevice.SetRenderTarget(myRenderTarget); |
1 | GraphicsDevice.SetRenderTarget(0, colorRT); |
2 | GraphicsDevice.SetRenderTarget(1, depthRT); |
1 | GraphicsDevice.SetRenderTargets(colorRT, depthRT); |
4 | GraphicsDevice.SetRenderTarget(0, null ); |
6 | GraphicsDevice.SetRenderTarget( null ); |
1 | GraphicsDevice.ResolveBackBuffer(depthMap); |
1 | GraphicsDevice.Textures[1] = depthMap; |
2 | Viewport viewport = GraphicsDevice.Viewport; |
3 | dofEffect.CurrentTechnique = depthBlurTechnique; |
4 | DrawFullscreenQuad(sceneMap, viewport.Width, viewport.Height, dofEffect); |
1 | GraphicsDevice.SetRenderTarget( null ); |
01 | GraphicsDevice.Textures[1] = depthMap; |
02 | GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp; |
03 | Viewport viewport = GraphicsDevice.Viewport; |
04 | dofEffect.CurrentTechnique = depthBlurTechnique; |
05 | DrawFullscreenQuad(sceneMap, viewport.Width, viewport.Height, dofEffect); |
08 | ResolveTexture2D resolveTarget; |
09 | RenderTarget2D renderTarget1; |
10 | RenderTarget2D renderTarget2; |
13 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
15 | int width = pp.BackBufferWidth; |
16 | int height = pp.BackBufferHeight; |
17 | SurfaceFormat format = pp.BackBufferFormat; |
20 | resolveTarget = new ResolveTexture2D(GraphicsDevice, width, height, 1, format); |
26 | renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, 1,format); |
27 | renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, 1,format); |
30 | GraphicsDevice.ResolveBackBuffer(resolveTarget); |
33 | RenderTarget2D sceneRenderTarget; |
34 | RenderTarget2D renderTarget1; |
35 | RenderTarget2D renderTarget2; |
38 | PresentationParameters pp = GraphicsDevice.PresentationParameters; |
40 | int width = pp.BackBufferWidth; |
41 | int height = pp.BackBufferHeight; |
42 | SurfaceFormat format = pp.BackBufferFormat; |
45 | sceneRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, false , |
46 | format, pp.DepthStencilFormat, pp.MultiSampleCount, |
47 | RenderTargetUsage.DiscardContents); |
53 | renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, false , format, DepthFormat.None); |
54 | renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, false , format, DepthFormat.None); |
57 | GraphicsDevice.SetRenderTarget(sceneRenderTarget); |
58 | GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; |
VertexDeclaration, Vertices, VertexElements, SizeInBytes 03 | GraphicsDevice.VertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexElements); |
09 | GraphicsDevice.VertexDeclaration = vertexDeclaration; |
10 | GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionTexture.SizeInBytes); |
13 | GraphicsDevice.SetVertexBuffer(vertexBuffer); |
17 | vertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.VertexElements); |
20 | vertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements()); |
24 | GraphicsDevice.VertexDeclaration = null ; |
25 | GraphicsDevice.Vertices[0].SetSource( null , 0, 0); |
28 | GraphicsDevice.SetVertexBuffer( null ); |
32 | VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[100]; |
35 | vertexBuffer.SetData<VertexPositionNormalTexture>(VertexPositionNormalTexture.SizeInBytes * vertexCount, |
36 | vertices,vertexCount,count,VertexPositionNormalTexture.SizeInBytes); |
39 | VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[100]; |
42 | vertexBuffer.SetData<VertexPositionNormalTexture>(vertices); |
1 | VertexBuffer, StreamOffset, VertexStride, IndexBuffer, BaseVertex |
03 | foreach (ModelMeshPart meshPart in mesh.MeshParts) |
06 | if (meshPart.PrimitiveCount > 0) |
09 | GraphicsDevice.VertexDeclaration = meshPart.VertexDeclaration; |
10 | GraphicsDevice.Vertices[0].SetSource(mesh.VertexBuffer, meshPart.StreamOffset, meshPart.VertexStride); |
11 | GraphicsDevice.Indices = mesh.IndexBuffer; |
14 | GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; |
17 | foreach (ModelMeshPart meshPart in mesh.MeshParts) |
20 | if (meshPart.PrimitiveCount > 0) |
23 | GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer); |
24 | GraphicsDevice.Indices = meshPart.IndexBuffer; |
29 | GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, |
30 | meshPart.BaseVertex, 0, meshPart.NumVertices, |
31 | meshPart.StartIndex, meshPart.PrimitiveCount); |
34 | GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, |
35 | meshPart.VertexOffset, 0, meshPart.NumVertices, |
36 | meshPart.StartIndex, meshPart.PrimitiveCount); |
Points, PointSpriteEnable, PointSizeMax, PointList 03 | vertexBuffer = new VertexBuffer(GraphicsDevice, typeof (VertexPositionNormalTexture), |
04 | 250, BufferUsage.WriteOnly | BufferUsage.Points); |
07 | vertexBuffer = new VertexBuffer(GraphicsDevice, typeof (VertexPositionNormalTexture), |
08 | 250, BufferUsage.WriteOnly | BufferUsage.None); |
12 | GraphicsDevice.RenderState.PointSpriteEnable = true ; |
13 | GraphicsDevice.RenderState.PointSizeMax = 128; |
19 | GraphicsDevice.DrawPrimitives(PrimitiveType.PointList, vertexPosition, numberVertices); |
22 | GraphicsDevice.DrawPrimitives(PrimitiveType.LineList, vertexPosition, numberVertices); |
OpenContainer, BeginShowStorageDeviceSelector, EndShowStorageDeviceSelector, Path, TitleLocation, FileStream 003 | StorageContainer storageContainer = storageDevice.OpenContainer( "YourGameName" ); |
008 | /// Synchronously opens storage container |
010 | private static StorageContainer OpenContainer(StorageDevice storageDevice, string saveGameName) |
012 | IAsyncResult result = storageDevice.BeginOpenContainer(saveGameName, null , null ); |
015 | result.AsyncWaitHandle.WaitOne(); |
017 | StorageContainer container = storageDevice.EndOpenContainer(result); |
020 | result.AsyncWaitHandle.Close(); |
026 | StorageContainer storageContainer = OpenContainer(storageDevice, "YourGameName" ); |
030 | Guide.BeginShowStorageDeviceSelector(GetStorageDeviceResult, retrievalDelegate); |
035 | StorageDevice.BeginShowSelector(GetStorageDeviceResult, retrievalDelegate); |
040 | storageDevice = Guide.EndShowStorageDeviceSelector(result); |
043 | storageDevice = StorageDevice.EndShowSelector(result); |
047 | string [] filenames = Directory.GetFiles(storageContainer.Path, "LevelSetup*.xml" ); |
050 | string [] filenames = storageContainer.GetFileNames( "LevelSetup*.xml" "); |
054 | using (FileStream stream = new FileStream(Path.Combine(storageContainer.Path, levelFilename), FileMode.Create)) |
056 | new XmlSerializer( typeof (SaveGameLevel)).Serialize(stream, levelData); |
060 | using (Stream stream = storageContainer.OpenFile(levelFilename, FileMode.Create)) |
062 | new XmlSerializer( typeof (SaveGameLevel)).Serialize(stream, levelData); |
067 | using (StorageContainer storageContainer = storageDevice.OpenContainer( "saveGameName" )) |
069 | File.Delete(Path.Combine(storageContainer.Path, saveGameLevel.FileName)); |
071 | File.Delete(Path.Combine(storageContainer.Path, "SaveGameLevel" + |
072 | Path.GetFileNameWithoutExtension(saveGameLevel.FileName).Substring(8) + ".xml" )); |
076 | using (StorageContainer storageContainer = OpenContainer(storageDevice, "saveGameName" )) |
078 | storageContainer.DeleteFile(saveGameLevel.FileName); |
080 | storageContainer.DeleteFile( "SaveGameLevel" + |
081 | Path.GetFileNameWithoutExtension(saveGameLevel.FileName).Substring(8) + ".xml" ); |
094 | levelPath = String.Format( "Levels/{0}.txt" , ++levelIndex); |
095 | levelPath = Path.Combine(StorageContainer.TitleLocation, "Content/" + levelPath); |
096 | if (File.Exists(levelPath)) |
101 | throw new Exception( "No levels found." ); |
112 | level = new Level(Services, levelPath); |
117 | levelIndex = (levelIndex + 1) % numberOfLevels; |
124 | string levelPath = string .Format( "Content/Levels/{0}.txt" , levelIndex); |
125 | using (Stream fileStream = TitleContainer.OpenStream(levelPath)) |
126 | level = new Level(Services, fileStream, levelIndex); |
133 | if ((storageDevice == null ) || !storageDevice.IsConnected) |
139 | using (StorageContainer storageContainer = storageDevice.OpenContainer(Session.SaveGameContainerName)) |
142 | string descriptionFilename; |
145 | if (overwriteDescription == null ) |
147 | int saveGameIndex = 0; |
152 | testFilename = Path.Combine(storageContainer.Path, "SaveGame" + saveGameIndex.ToString() + ".xml" ); |
154 | while (File.Exists(testFilename)); |
155 | filename = testFilename; |
156 | descriptionFilename = "SaveGameDescription" + saveGameIndex.ToString() + ".xml" ; |
160 | filename = Path.Combine(storageContainer.Path, overwriteDescription.FileName); |
161 | descriptionFilename = "SaveGameDescription" + |
162 | Path.GetFileNameWithoutExtension(overwriteDescription.FileName).Substring(8) + ".xml" ; |
165 | using (FileStream stream = new FileStream(filename, FileMode.Create)) |
167 | using (XmlWriter xmlWriter = XmlWriter.Create(stream)) |
174 | SaveGameDescription description = new SaveGameDescription(); |
175 | description.FileName = Path.GetFileName(filename); |
176 | description.ChapterName = IsQuestLineComplete ? "Quest Line Complete" : Quest.Name; |
177 | description.Description = DateTime.Now.ToString(); |
179 | using (FileStream stream = new FileStream(Path.Combine(storageContainer.Path, descriptionFilename), FileMode.Create)) |
181 | new XmlSerializer( typeof (SaveGameDescription)).Serialize(stream, description); |
188 | if ((storageDevice == null ) || !storageDevice.IsConnected) |
194 | using (StorageContainer storageContainer = OpenContainer(storageDevice, Session.SaveGameContainerName)) |
197 | string descriptionFilename; |
199 | if (overwriteDescription == null ) |
201 | int saveGameIndex = 0; |
206 | testFilename = "SaveGame" + saveGameIndex.ToString() + ".xml" ; |
208 | while (storageContainer.FileExists(testFilename)); |
209 | filename = testFilename; |
210 | descriptionFilename = "SaveGameDescription" + saveGameIndex.ToString() + ".xml" ; |
214 | filename = overwriteDescription.FileName; |
215 | descriptionFilename = "SaveGameDescription" + |
216 | Path.GetFileNameWithoutExtension(overwriteDescription.FileName).Substring(8) + ".xml" ; |
220 | using (Stream stream = storageContainer.OpenFile(filename, FileMode.Create)) |
222 | using (XmlWriter xmlWriter = XmlWriter.Create(stream)) |
229 | SaveGameDescription description = new SaveGameDescription(); |
230 | description.FileName = Path.GetFileName(filename); |
231 | description.ChapterName = IsQuestLineComplete ? "Quest Line Complete" : Quest.Name; |
232 | description.Description = DateTime.Now.ToString(); |
235 | using (Stream stream = storageContainer.OpenFile(descriptionFilename, FileMode.Create)) |
237 | new XmlSerializer( typeof (SaveGameDescription)).Serialize(stream, description); |
1 | VertexShader, PixelShader, ps_1_x |
02 | VertexShaderOutput VertexShader(...) |
06 | float4 PixelShader(...) |
12 | VertexShaderOutput VertexShaderFunction(...) |
17 | float4 PixelShaderFunction(...) |
27 | VertexShader = compile vs_1_1 VertexShader(); |
28 | PixelShader = compile ps_1_1 PixelShader(); |
36 | VertexShader = compile vs_2_0 VertexShaderFunction(); |
37 | PixelShader = compile ps_2_0 PixelShaderFunction(); |
XNA Model drawn inside out, slightly transparent, missing parts or just looks wrong 2 | GraphicsDevice.BlendState = BlendState.Opaque; |
3 | GraphicsDevice.DepthStencilState = DepthStencilState.Default; |
|