This project is read-only.

Tutorial: Add Animated Creeps

Mar 7, 2012 at 8:23 AM

As there was a certain request here is how I brought animated Creeps into the Game. This is not going to be a "copy all the code -> working" thread, I will give you a pseudocodish step by step instruction but coding will happen on your side ;)

There are some assumtions I made:

  • The creep has 3 animations: Normal, Low (played when under 30% health) and a death animation
  • Each animations is in its own file
  • Animations are oneliner (just like explosion.png) 

Shorty about how the enemyXML -> enemyData : Contentpipeline imports and read xml, then it processes the strings from the xml into textures in an enemyContent object and write this into the compiled content file. This file can be opened and is written into enemeyData.

Ok now a step by step instruction:

  1. In ContentPipeline Project
    1. In Enemy Content add 3 Textures for our 3 animations.
    2. under " [ContentSerializerIgnore]" add 3 strings for the texture paths.
    3. Now open EnemyImporter and in the part where all the tag are read copy  "TexturePath = e.Attribute("Texture").Value" 3 times and rename "Texture" into the corresponding names of your animation tags ("deathAnimation","lowAnimation" and "normalAnimation" for me).
    4. Go into EnemyProcessor and copy the texture loading stuff 3 times and change variales to match your fields.
    5. Last but not least here open the EnemyDataWriter and again copy " output.WriteObject(value.Texture);" three time and change "value.Texture" into your field.
  2. Now switch to Engine Project
    1. Add 3 Animated Sprites to EnemyData.cs
    2. Open EnemyDataReader and add a function which generates a looping AnimatedSprite from a texture. then call this function in new EnemyData part, passing the textures with "input.ReadObject<Texture2D>()". Make sure you keep the order you wrote it to the stream in the EnemyDataWriter.

Now you have your enemyData populated with AnimatedSprites. All you need to do now is open up GameVisuals and add you drawing logic. This is left as an excercise to the thoughtful reader ;)

Hope this helps you a bit with getting startet!

Regards floAr