Saturday, 2 October 2010

XNA Tile Engine Base Solution Updates

I've done a little more work on my XNA Tile Engine for WIndows Phone 7, and I've also branched it off into a solution for Windows and Xbox, which I've dubbed "HiDefTileBase".

The HiDef solution contains an additional example mode showcasing a platform game running on the engine. It's important to note that both the RPG and Platform examples are using the exact same classes for drawing the tilemap and controlling the camera - only the GameplayScreen and Player classes differ to reflect the actual game mechanics.


I've added an example of a day/night cycle into the RPG game in both the Phone 7 and HiDef solutions, and made some optimizations to the map drawing routine as it was getting rather slow when several layers were being drawn. All looks good now, although performance on Phone 7 hardware is still a mystery :)

The two new downloads are after some screenshots:




Please note that the solution is built on XNA 4.0 and will not compile using older versions of the XNA SDK.

Hi-Def (Xbox & Windows) solution: http://team-mango.com/stuff/hideftilebase.zip


22 comments:

yoann said...

Hello,

I'm trying to use your 2D game engine, it looks great but (there si always a but :( ) :

I don't undertand why when i'm trying to use it, on compilation i'm getting this error

"Erreur 1 Building content threw FormatException: Le format de la chaîne d'entrée est incorrect.
à System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt)
à System.Single.Parse(String s)
à TiledContentPipeline.LayerContent..ctor(XmlNode node) dans F:\HiDefTileBase\TiledContentPipeline\Content Types\LayerContent.cs:ligne 25
à TiledContentPipeline.TileLayerContent..ctor(XmlNode node) dans F:\HiDefTileBase\TiledContentPipeline\Content Types\TileLayerContent.cs:ligne 12
à TiledContentPipeline.MapContent..ctor(XmlDocument document) dans F:\HiDefTileBase\TiledContentPipeline\Content Types\MapContent.cs:ligne 55
à TiledContentPipeline.TmxProcessor.Process(XmlDocument input, ContentProcessorContext context) dans F:\HiDefTileBase\TiledContentPipeline\TmxProcessor.cs:ligne 22
à Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context)
à Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
à Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
à Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
à Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings) F:\HiDefTileBase\HiDefTileBase\HiDefTileBaseContent\Maps\TestMap.tmx Windows Copy of HiDefTileBase"

(Yep sorry it's in French =) )
It seems that there is an error on decoding Testmap.tmx.
he fact is that I did'nt look at how maps are defined but This error on compiling your example is stucking me :)

I would be very pleased if you could explain me were I lame.

Gareth said...

Hi!

This will be a Globalization issue. The French regional settings are probably expecting a , instead of a . as a floating point separator.

Try changing line 25 of TiledContentPipeline\ContentTypes\LayerContent from:

Opacity = float.Parse(node.Attributes["opacity"].Value);

to:

Opacity = float.Parse(node.Attributes["opacity"].Value, CultureInfo.InvariantCulture);

and see if it gets past it. If that line builds okay, there are other places in the solution that also use float.Parse(), so you'll need to change the same thing throughout.

yoann said...

Thanks for your answer.

I changed
Opacity = float.Parse(node.Attributes["opacity"].Value);

to:

Opacity = float.Parse(node.Attributes["opacity"].Value, System.Globalization.CultureInfo.InvariantCulture);

It passed but, now i'm getting :

Erreur 1 Missing asset "F:\HiDefTileBase\HiDefTileBase\HiDefTileBaseContent\Tileset.png". F:\HiDefTileBase\HiDefTileBase\HiDefTileBaseContent\Maps\TestMap.tmx Windows Copy of HiDefTileBase

I'm seriously thinking about deleting this french version to an english one :)

Is it still linked to Globalization ?

Gareth said...

Check this setting on both of the .tmx content files. The TileSet directory should be "TileSets". That's all I can think of for that one.

yoann said...

Hi again,
after trying different kind of way to make it work, I made another project including your engine with the example.

As you told me I placed some "System.Globalization.CultureInfo.InvariantCulture"
when a float.Parse() was involved in an error.

The error with the .tmx was entirely my fault, I don't know why but when I unzipped your Engine the first time, both .tmx were'nt in the folder, so I just drag 'n dropped them in the project ^^ A newb reflex.

Anyway thanks for your support, maybe I will ask you some help when I won't understand how your engine works because it comes without any documentation (When I'll be trained with it, maybe I could give you a hand to continue to improve it (if it is needed :) ).

Another question is that i'm looking for making a Metroïd-like plateform game, with which license is your engine ? Anyway, you'll get some credits ;)

Joe Zack said...

I've been having a lot of fun with your TileEngine!

Unknown Courier said...

Hi Gareth,

Just wondering if I can use your tile engine to make a game for re-selling or is for non commercial purposes only.

Si

Gareth said...

As far as I'm concerned, all my code is free-to-use for anything. It's based on the Gamestate Management sample, which is also free to use but you may want to read the license for that on the App Hub.

Then there's Nick Gravelyns code for loading Tiled maps. His blog post about it is here:
http://blog.nickgravelyn.com/2010/03/know-when-to-be-lazy/

That should cover everything I've used as far as permissions are concerned.

Nick K said...

I wrote a little blog post about some of your stuff here, thought you might enjoy knowing~ I have a number of students competing in Microsoft's ImagineCup, and I've been directing some of them towards your framework. Thanks for making public awesome stuff like this!

Stoney said...

I'm trying to find out how to replace your TestMap and TileSet for the RPG, but switching out the files doesn't seem to work. What am I missing?

Gareth said...

Need more information, but to hazard a guess I'd say you need to set the TileSet directory in the Content Processor properties of the map when you include it in your Content project. Take a look at the properties of the maps in the original projects.

robin_vj said...
This comment has been removed by the author.
Gareth said...

Going to reply to a post that was removed, just to help those with the same question.

With regards to how collision and parallax scrolling work in the engine, pay very close attention to the properties on layers in the test maps supplied with the solution in Tiled.

For collision detection, you need to set a property called "Collision" with a value of "On" on the layer you want collisions active on.

You also need to set a property on the FIRST (top-left most) tile of each tileset you want to generate collision data for. That property should be called "CollisionSet" and have a value of "True". I had to do it that way because you can't set properties on tilesets themselves, only single tiles.

You can out how all the other stuff works by looking at the draw and player movement code in the solution.

robin_vj said...

Hey,
Great engine if been messing around with it but i cant seem to figure out how to add a "Light" to the game, i want to add a light just like the one on the playersprite but i want to be able to place it somewere on the map like with vector 2, any ideas?

robin_vj said...

Sorry for spamming, googleaccount seems to mess up comments, i deleted the other comment because on my screen it didnt show on the comments, and i figured it out. Keep it up!
you may delete this post if you want.

69942284-7144-11e0-a58b-000bcdcb471e said...

This is absolutely amazing. I just wish I knew how to use it =(

would there be anyone willing to chat with me for a little while, to answer a few questions on utilizing this engine? I've been looking at the code, and while I'm starting to wrap my head around it I'm still pretty confused.

If anyone is willing I would really appreciate it. My email is johnnyyr_game at yahoo.com.

Thanks!

69942284-7144-11e0-a58b-000bcdcb471e said...

Sorry, email is johnnyr_game at yahoo.com

dubca7 said...

I want to try this engine out soooo bad, but when I try to compile i get this error [CODE]Error 1 Building content threw InvalidOperationException: Cyclic reference found while serializing System.Xml.XmlDocument. You may be missing a ContentSerializerAttribute.SharedResource flag.
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value, ContentTypeWriter typeWriter)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriterMemberHelper.Write(ContentWriter output, Object parentInstance)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriter.Write(ContentWriter output, Object value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriter.Write(ContentWriter output, Object value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriter.Write(ContentWriter output, Object value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.InvokeWriter[T](T value, ContentTypeWriter writer)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value, ContentTypeWriter typeWriter)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriterMemberHelper.Write(ContentWriter output, Object parentInstance)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriter.Write(ContentWriter output, Object value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ReflectiveWriter.Write(ContentWriter output, Object value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.InvokeWriter[T](T value, ContentTypeWriter writer)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value)
at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentCompiler.Compile(Stream output, Object value, TargetPlatform targetPlatform, GraphicsProfile targetProfile, Boolean compressContent, String rootDirectory, String referenceRelocationPath)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.SerializeOutputAsset(BuildItem item, Object assetData, String outputFilename)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.SerializeAsset(BuildItem item, Object assetData)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings) c:\users\kim\documents\visual studio 2010\Projects\HiDefTileBaseGame\HiDefTileBaseGame\HiDefTileBaseGameContent\Maps\TestMap.tmx HiDefTileBaseGame[/CODE]

Do you know anyway around this ?

Nexus1216 said...

Hey I'm having trouble figuring how to add more tile sets. Ive tried to set the tile and layers like you suggested but nothing i get no collisions (i also tried to check what the properties were on the wall layer and TileSet1 and it appears they do not have any properties configured)

what would be the proper way to enter a house or dungeon (would you use an object (placed on top of the tile that represent the door) that loads another screen?

sorry for all the questions (i'm a noob)

Either way great source code thanks for putting it out there

Tony Doangzz said...

hmm sir sorry for asking this much but can you make a tutorial for using this tile engine? coz i really confuse when i looking at your solution....

Scott Lafoy said...

Hi there, I see I am a little late to the party here but figured I would try anyway. I think a lot of people are still coming across this and trying it out so it may be of use to a few people.

First off, thank you for releasing your engine, it is very handy using tiled to make maps.

My first question is regarding the camera when using maps larger then your demo map. I noticed that just switching the map to 100 by 100 the player can only walk around the size of the original demo map. I believe the line of code responsible for the view area is the following:
// Initialise camera using a custom rectangle to define the boundaries
gameCamera = new Camera(ScreenManager.GraphicsDevice.Viewport, new Rectangle(1 * gameMap.TileWidth, 1 * gameMap.TileHeight, 49 * gameMap.TileWidth, 29 * gameMap.TileHeight));

Now by playing with the values (49 and 29) you can get it close to what you want but I am curious as to if this is the correct spot and what those values mean so I can calculate the values for the different sized maps I will use in my project.

My second question is, it seams that when including 2 maps in the project that reference the same tile set it will not compile. Is there a way to do this other then including multiple copies of the same tile set named differently?

Thank you for your time.

for IT the said...

I have read your blog its very attractive and impressive. I like it your blog.

Dot Net Training in Chennai Dot Net Training in Chennai .Net Online Training .Net Online Training Dot Net Training in Chennai Dot Net Training in Chennai


Dot Net Online Training Dot Net Online Training LINQ Online Training LINQ Online Training ASP.NET Online Training ASP.NET Online Training