Archive

Archive for September, 2010

XNA 3.1 to XNA 4 Post Conversion

September 29th, 2010 admin No comments

Although it compiles and now runs, there are still a few edits required. The obvious problems are visual and result in problems with the transparency of the 3D tiles. 

        GraphicsDevice.RenderState.AlphaBlendEnable = true;   

is no longer valid and I had not replaced all with the new alternative: 

         GraphicsDevice.BlenState = BlendState.AlphaBlend; 

Some 3D tile objects were transparent to other 3D objects. This was due to the removal of: 

         GraphicsDevice.RenderState.DepthBufferEnable = true;

In XNA 4 this was replaced by:

         DepthStencilState depthBufferState;
         depthBufferState = new DepthStencilState(); 
         depthBufferState.DepthBufferEnable = true;
         GraphicsDevice.DepthStencilState = depthBufferState;

And now everything works again. Simple!

Categories: XNA 4 Tags:

XNA 3.1 to XNA 4 Conversion

September 28th, 2010 admin No comments

Here are notes on code that I needed modify to allow me to move from XNA 3.1 to XNA 4:

The name ‘SpriteBlendMode’ does not exist in the current context

This is due to a change to SpriteBatch.Begin.  The SpriteBlendMode enum is now gone and we should now specify the state object directly. Also SaveStateMode is now also not required.

XNA 3.1: spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
XNA 4:   spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,null,null,null);

‘Microsoft.Xna.Framework.Graphics.RenderTarget2D’ does not contain a constructor that takes 5 arguments

XNA 3.1 :renderTarget = new RenderTarget2D(device, 512, 512, 1, SurfaceFormat.Color);

RenderTarget2D now inherits direct from Texture2D. 

‘Microsoft.Xna.Framework.Graphics.GraphicsDevice’ does not contain a definition for ‘RenderState’ and no extension method ‘RenderState’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice’ could be found

XNA 3.1 :graphics.GraphicsDevice.RenderState.AlphaBlendEnable =false;

Error 10 ’Microsoft.Xna.Framework.Graphics.BasicEffect’ does not contain a definition for ‘Begin’ and no extension method ‘Begin’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.BasicEffect’ could be found

 

Error 15 ’Microsoft.Xna.Framework.Graphics.EffectPass’ does not contain a definition for ‘End’ and no extension method ‘End’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.EffectPass’ could be found 

XNA 3.1: effectPass.Begin();
XNA 4: effectPass.Apply(); 

XNA 3.1: effectPass.End();   No longer required to begin and end the effect.

BasicEffect has been extended for XNA 4.0 to support 20 vertex shaders (was 12) and 10 pixel shaders (was 4), mainly due to the inclusion of Windows Phone 7 to be supported by the framework.

 

Error 35 ’Microsoft.Xna.Framework.Graphics.BasicEffect’ does not contain a constructor that takes 2 arguments Now only 1 argument   

XNA 3.1: new BasicEffect(GraphicsDevice, null);

XNA 4: new BasicEffect(GraphicsDevice);

The EffectPool is no longer required, even if it was only ever null in my cases

 

Error 39 ’Microsoft.Xna.Framework.Graphics.EffectPass’ does not contain a definition for ‘Begin’ and no extension method ‘Begin’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.EffectPass’ could be found

XNA 3.1: effect.Begin(); 

XNA 3.1: effect.End();   No longer required to begin and end the effect.

 

Error 35 ’Microsoft.Xna.Framework.GameTime’ does not contain a definition for ‘ElapsedRealTime’ and no extension method ‘ElapsedRealTime’ accepting a first argument of type ‘Microsoft.Xna.Framework.GameTime’ could be found

 

Error 36 ’Microsoft.Xna.Framework.GameTime’ does not contain a definition for ‘TotalRealTime’ and no extension method ‘TotalRealTime’ accepting a first argument of type ‘Microsoft.Xna.Framework.GameTime’ could be found

ElapsedRealTime and TotalRealTime nolonger supported by the GameTime class. In my case it was OK to use ElapsedGameTime and TotalGameTime. Alternatively .Net timer API could be used if really need ‘real’ time. 

 

Error 24 ’Microsoft.Xna.Framework.Graphics.VertexPositionTexture’ does not contain a definition for ‘SizeInBytes’ 

VertexBuffer is now a stronly typed container using an associated VertexDeclation. This was not the case prior to XNA 4.0:

XNA 3.1: vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, VertexPositionTexture.SizeInBytes * hexVertices.Length, BufferUsage.WriteOnly);

XNA 4: vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionTexture), 36, BufferUsage.WriteOnly);

 

Error 88 ’Microsoft.Xna.Framework.Graphics.VertexPositionTexture’ does not contain a definition for ‘VertexElements’ 

XNA 3.1: hexVertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionTexture.VertexElements); 

VertexDeclaration constructor no longer needs a GraphicsDevice.

 

Error 56 ’Microsoft.Xna.Framework.Graphics.GraphicsDevice’ does not contain a definition for ‘VertexDeclaration’ and no extension method ‘VertexDeclaration’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice’ could be found

XNA 3.1: graphics.GraphicsDevice.VertexDeclaration = hexTiles.hexVertexDeclaration;

No longer required at all as associated declaration will automatically be found by the associated device. We can now delete the above graphics.GraphicsDevice.VertexDeclarion.

 

Error 11 ’Microsoft.Xna.Framework.Graphics.VertexPositionTexture’ does not contain a definition for ‘VertexElements’ 

XNA 3.1: hexVertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionTexture.VertexElements);

The initial 165 compile ‘errors’ were soon reduced to zero by resolving the above.

Now all compiles well but still a few visual problems mainly with tile transparency. Previously this was controlled by GraphicsDevice.RenderState.AlphaBlendableEnable which is no more.

Categories: XNA 4 Tags:

Reboot

September 12th, 2010 admin No comments

Today was planned to be the first day that I can devote to Hexworld again since mid July. The last 2 months have been hectic with a constant stream of visitors, and visits to Switzerland and Russia. Of course I could not work amongst all the traffic and so had to devote my time to some “game testing” (Bad Company, Civilization Revolution and Ruse). However  I note that the XNA 4 RTM is available within a few days, and I think it would be better to reboot myself into the latest tool. I also have taken some time out looking at Windows Phone 7 and iPhone development but forced myself to concentrate on completing the XBox project first.

It was encouraging to see that XBox Live Arcade game Castle Crashers has now sold 1,854,000 units. This is an average game achieveable by someone with reasonable graphics and programming ability. Yet Toy Soldiers achieved only 329,000 units- strange. Onwards, best get started before Civ 5 is released……..

Categories: Thinking aloud Tags:

Layering a Hex grid on the World

September 9th, 2010 admin No comments

Here I will consider different methods of laying a hexgrid on a sphere. There are several reasons that you may want to do this:

a) To play a game on an existing system such as Google Earth
b) Regulate movement within your own game
c) To use as a system to import real maps into your own games.

Our planet is not a true sphere but for our puposes we will assume it and all other planets we encounter are regular spheres.

Using an Icosahedron
An Icosahedron is a 20 sided regular polygon, each face being an equilateral triangle. This shape will be familiar to wargamers that like to use 20 sided die.
This is not a perfect solution as the hexagons will not fit unless a pentagon is used at each apex of the Icosahedron.
The real advantage of this system is that you may use any scale that you choose, ie each of the 12 triangular sides within the Icosahedron may include as many hexagons as you wish, noting that the apex of each triangle will be a pentagon and not a hexagon.  For more detail search for Icosahedron Snyder or Geodesic.

This is not a solution if you want to zoom out to see an entire planet, as you will then see a flat sided planet. 

To Be Continued… 

 

Categories: Map, Mathmatical Theory Tags: