Thursday, January 21, 2010

My upgrades to XNA 2D beginners tutorial

I used a XNA 2D beginners tutorial and changed it to a more generic and flexible code.
I also added explosions and sound.
The new classes I created can be used for any 2D XNA game.
The tutorial is here: http://creators.xna.com/en-US/education/gettingstarted/bg2d/chapter1Explanations and demo of explosions: http://creators.xna.com/en-US/sample/particle
The demo project with the new classes: http://www.megaupload.com/?d=NEMV4EF3
Screenshot:


Most of the code can't be figured from the screenshot.
I created some generic classes to represent static objects, moving objects, particles, and particles systems. I wrote the most important things about some classes:
  • class GameObject2 : DrawableGameComponent
    • Represents a static 2D object
    • Has the following additional properties:
      • Texture
      • Position
      • Center
      • Rotation
      • Scale
      • DestinationRectangle
      • CenterPosition
      • Active
      • SourceRectangle
      • Color
      • Effects
      • LayerDepth
      • SpriteBlendMode
    • Has 8 different constructors for different purposes
    • Overrides Draw() method


  • class MovingGameObject2 : GameObject2
    • Represents an 2D object that moves
    • Has the following additional properties:
      • Velocity
      • Acceleration
      • RotationSpeed
      • TimeSinceInit
    • Overrides Update() method
    • class Particle2 : MovingGameObject2
      • Represents a 2D particle like in an explosion
      • Has a Lifetime property
      • Overrides Update() method
    • abstract class ParticleSystem2 : GameObject2
      • Represents a 2D particle system that can be used for explosions, smoke etc.
      • Has the following protected parameters:
        • rangeParticlesPerEffect
        • rangeVelocity
        • rangeAcceleration
        • rangeRotation
        • rangeRotationSpeed
        • rangeScale
        • rangeLifetime
      • Each new particle gets a random value for each parameter from its range
      • Overrides Draw() and Update() methods

      Tuesday, January 5, 2010

      How to restore Visual Studio .sln file icon

      I merely tried to associate .sln file type with the IDE so Windows 7 taskbar will remember my recent projects and I could access them with right click. I ended up reinstalling Visual Studio. This was after I tried to fix it in registry, just to find out Windows 7 has a different mechanism for file types associations. The big frustration was I could not find the icons themselves to put them on the registry. Visual Studio has a "Restore File Associations" feature. It doesn't fix the icons! Reinstalling after deleting all related registry values didn't work either! After a couple of hours where I visited sites like Ways Bill Gates Should Die, and Googling a lot I found the solution:

      1. Right click a .sln file
      2. Click "Open with..."
      3. Click "Browse..."
      4. Go to "Program Files\Common Files\microsoft shared\MSEnv"
      5. Choose "VSLauncher.exe"
      6. Click "Open"
      7. Check "Always use the selected program to open this kind of file"
      8. Click "OK"