Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You would probably want to use a DrawableGameObject</p> <pre><code>public class Snowman : DrawableGameObject { private Camera cam = new Camera(); //Model snowMan; //Matrix[] snowManMatrix; public Model snowMan {get;set;}; public Matrix[] snowManMatrix{get;set;}; protected override void LoadContent() { //snowMan = Content.Load&lt;Model&gt;( "Models\\snowman" ); snowManMatrix = new Matrix[ snowMan.Bones.Count ]; snowMan.CopyAbsoluteBoneTransformsTo( snowManMatrix ); } public void DrawSnowMan(Model model, GameTime gameTime) { foreach (ModelMesh mesh in model.Meshes) { Matrix world, scale, translation; scale = Matrix.CreateScale(0.02f, 0.02f, 0.02f); translation = Matrix.CreateScale(0.0f, 0.7f, -4.0f); world = scale * translation; foreach (BasicEffect effect in mesh.Effects) { effect.World = snowManMatrix[mesh.ParentBone.Index] * world; effect.View = cam.viewMatrix; effect.Projection = cam.projectionMatrix; effect.EnableDefaultLighting(); } mesh.Draw(); } } protected override void Draw(GameTime gameTime) { DrawSnowMan( snowMan, gameTime ); } } </code></pre> <p><strong>In Game1.cs</strong></p> <p>Initialize</p> <pre><code> Snowman snowDude= new Snowman(); Components.Add(snowDude); </code></pre> <p>And move </p> <pre><code> //snowDude = Content.Load&lt;Model&gt;( "Models\\snowman" ); snowDude.snowMan = Content.Load&lt;Model&gt;( "Models\\snowman" ); </code></pre> <p>into Game1's LoadContent</p> <p>Adding to Components means that snowDude's Update and Draw are called whenever Game1's is. I am honestly not 100% on in what order though. I believe Load Content should be called as well but I think it is better practice (at least while you're learning) to import all of your sounds/animations/sprites in the same place (in your main file) so that you know exactly what is being called and when.</p> <p><strong>OR</strong> instead of Components.Add(snowDude);</p> <p>You can just call snowDude.Draw(gametime) in Game1's Draw Method. and snowDude.Update() in Game1's Update method.</p> <p>And otherwise I agree with Brent. If there are only Snowmen then you should be fine with only one class but if you start adding more there will be a lot of overlap, so making an Enemy Class</p> <pre><code>public class Enemy: DrawableGameObject{} </code></pre> <p>and changing SnowMan to </p> <pre><code>public class SnowMan:Enemy{} </code></pre> <p>should be appropriate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload