Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is hard to see what is wrong with your code, because it contains two versions in one. Clean it up a bit. Here are some tips:</p> <p>You don't want to use DrawableGameComponent for individual objects, in my experience. Stick to writing your own classes and putting them in collections or something like that. This way, you don't have to deal with the voodoo of XNA firing off your update and draw for you. Better to control that yourself.</p> <p>You don't want your CAR to handle View- and Projection-Matrices. Leave those in your Game-class (for now. there should be a camera-class instead) and pass them to your Car.Draw-method. I see you pass it in the constructor, but Matrixes are value-types, as far as I can remember, and so changes to your view in other parts of the code would not propagate to your car.</p> <p>so change Car.Draw to:</p> <pre><code>public void Draw(Matrix view, Matrix projection) { DrawModel(view, projection); } </code></pre> <p>As you might get from my changes to draw, you should also make DrawModel a normal method (remove static), so that it don't have to receive model and world.</p> <p>Your Car should have a Quaternion or similar for rotation. The Car.World can thus be written:</p> <pre><code>Matrix World = Matrix.Identity; //In update: World = Matrix.FromQuaternion(Rotation) * Matrix.CreateTranslation(Position); </code></pre> <p>Let Car's constructor take a Model as a parameter. That way you can also ditch "GameParent" and the LoadContent-Method.</p> <p>In you game-class:</p> <p>Ditch the static DrawModel-method. Ditch the fields world and car. they belong to the Car-class now.</p> <p>Make a field (class-level variable that is not a property) for your car:</p> <pre><code>Car MyCar = null; </code></pre> <p>In Game1.LoadContent:</p> <pre><code>MyCar = new Car(Content.Load&lt;Model&gt;("car//car")); </code></pre> <p>In Game1.Update:</p> <pre><code>MyCar.Update(gameTime); </code></pre> <p>In Game1.Draw:</p> <pre><code>GraphicsDevice.Clear(Color.CornFlowerBlue); MyCar.Draw(View, Projection); </code></pre> <p>Edit;</p> <p>For a game engine, you will normally have some "parts" that you currently are missing:</p> <ul> <li>Game State system (Menu is one type of state, NormalLevel and BossLeve are examples of others)</li> <li>Camera service (so you can get current view/projection matrices from anywhere) -Timing service (so you can get (float)gameTime.ElapsedGametime.TotalSeconds from anywhere)</li> <li>Input service (So you can get per-update input values from anywhere )</li> </ul> <p>A Camera-system can be as simple as:</p> <pre><code>public interface ICamera { Vector3 Position { get; } Matrix View { get; } Matrix Projection { get; } void Update(float deltaTime); void Target(Vector3 targetPosition); } public class CameraService { public static ICamera ActiveCamera { get; private set; } public static void ActivateCamera(ICamera camera) { if (ActiveCamera != null) camera.Target(ActiveCamera.Target); ActiveCamera = camera; } public static Update(float deltaTime) { if (ActiveCamera != null) ActiveCamera.Update(deltaTime); } } public class BasicCamera: ICamera { public Vector3 Position { get; protected set; } public Matrix View { get; protected set; } public Matrix Projection { get; protected set; } public void Target(Vector3 targetPosition) { View = Matrix.CreateLookAt(Position, targetPosition, something something); } public BasicCamera(Vector3 position, Vector3 target) { //Set shit up } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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