XNA Game Development Forums
2012/05/21 19:35:28 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Trouble with The ObjectComponent Class  (Read 3154 times)
Tyler
Newbie
*
Offline Offline

Posts: 6


View Profile
« on: 2007/05/29 08:19:37 »

Hey, I typing up The HazyMind Engine to learn XNA and then try an make my own Game Engine. Ive Run Into an error with the ObjectComponent Class( tut 2 ).

Code:
Quote
using Microsoft.Xna.Framework.Graphics;


namespace Engine.Objects.ObjectComponents
{
    interface IRenderable : IObjectComponent
    {
        void Render(GraphicsDevice device);
    }
}

Here is the error:
Quote
Error   2   The type or namespace name 'IObjectComponent' could not be found (are you missing a using directive or an assembly reference?)   C:\Users\tyler\Projects\Engine\Engine\ObjectComponents.cs   6   29   Engine


Thanks
Logged
daenris
Newbie
*
Offline Offline

Posts: 7


View Profile
« Reply #1 on: 2007/05/29 13:27:39 »

First off, just make sure your Namespaces match in the two files (IRenderable and IObjectComponent).  As the error says, it can't find that interface.  So assuming it does in fact exist (an there aren't any typos in the name anywhere), it should work as long as they're in the same namespace.

Can you post some more code, like the complete contents of your IObjectComponent file?
Logged
Tyler
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #2 on: 2007/05/29 14:06:52 »

Here I'll just post all the files i typed so far. Everything Ran Perfect Until ObjectComponents.cs. Sad



Game.cs:
Quote
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Engine
{
    public class EGame : Game
    {

        GraphicsDeviceManager graphics;

        public EGame()
        {
            graphics = new GraphicsDeviceManager(this);

            Window.AllowUserResizing = true;
            Window.ClientSizeChanged += new System.EventHandler(Window_ClientSizeChanged);
        }

        void Window_ClientSizeChanged(object sender,System.EventArgs e)
        {
            graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
            graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
        }

        protected override void Update(GameTime gameTime)
        {
            KeyboardState kState = Keyboard.GetState();
            if (kState.IsKeyDown(Keys.F))
            {
                graphics.ToggleFullScreen();
            }

            base.Update(gameTime);
        }


        protected override void Draw(GameTime gametime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            base.Draw(gametime);
        }
    }
}



ObjectComponents.cs:
Quote
using Microsoft.Xna.Framework.Graphics;


namespace Engine.Objects.ObjectComponents
{
    interface IRenderable : IObjectComponent
    {
        void Render(GraphicsDevice device);
    }
}


Objects.cs:
Quote
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Engine.Objects.ObjectComponents;

namespace Engine.Objects
{
    public class Object
    {
        protected Vector3 Position;
        protected Vector3 Scaling;
        protected Quaternion Rotation;

        public Object()
        {
            Position = new Vector3(0, 0, 0);
            Scaling = new Vector3(1, 1, 1);
            Rotation = new Quaternion(0, 0, 0, 1);
        }

        public void Draw(GraphicsDevice device)
        {
            if (this is IRenderable)
            {
                ((IRenderable)this).Render(device);
            }
        }
    }
}

The errors are in the first post. once i get this solved i will continue.
Logged
daenris
Newbie
*
Offline Offline

Posts: 7


View Profile
« Reply #3 on: 2007/05/29 14:42:09 »

You'll want to take another look at the Tutorial.  You're missing the actual IObjectComponent interface:

Code:
namespace HMEngine.HMObjects.HMObjectComponents {
        interface IHMObjectComponent {}
}
Logged
Tyler
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #4 on: 2007/05/29 14:49:32 »

 ok i got it to work Grin.

That was a really stupid mistake Huh
Logged
Tyler
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #5 on: 2007/05/29 16:09:34 »

Ok, i got another error, this time it is in my demo.

Code:
Quote
using Microsoft.Xna.Framework.Graphics;
using Engine.Objects.ObjectComponents;
using Engine.Objects;


namespace Engine.Objects
{
    public class TestObject : Object, IRenderable
    {
        public void Render(GraphicsDevice device)
        {
            device.Clear(Color.Orange);
        }
    }

    class Demo
    {
        static EGame game = new EGame();
        static TestObject test = new TestObject();

        public static void Main()
        {
            game.Scene.AddObject(test);
            game.Run();
        }
    }
}


error:
Quote
Error   1   'Engine.Objects.ObjectComponents.IRenderable' is inaccessible due to its protection level   C:\Users\tyler\Projects\Engine\ObjectDemo\ObectDemo.cs   8   39   ObjectDemo

Logged
daenris
Newbie
*
Offline Offline

Posts: 7


View Profile
« Reply #6 on: 2007/05/29 16:18:21 »

I believe, though I'm not 100% positive, that the Object declaration need to go into the Engine, rather then the Demo.  Because the interfaces (IRenderable, IObjectComponent, etc) aren't accessible outside the Engine itself.
Logged
Tyler
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #7 on: 2007/05/29 16:53:57 »

I don't get what your saying. I'm just creating the Engine and demos form the tutorials, so i don't know why it did not work.I must have done something wrong in the engine i'll double check.

all the code(engine) is in one of the post.
Logged
daenris
Newbie
*
Offline Offline

Posts: 7


View Profile
« Reply #8 on: 2007/05/29 19:47:33 »

Yeah, some of the tutorial code boxes are a bit confusing.  But you need to read the comments carefully.  The test object is created as a class in the Engine, not the demo.

Here's the relevant bit of code from the tutorial
Code:
using Microsoft.Xna.Framework.Graphics;
using HMEngine.HMObjects.HMObjectComponents;

namespace HMEngine.HMObjects {
   public class HMTestObject : HMObject, IHMRenderable{
      public void Render(GraphicsDevice myDevice) {
         myDevice.Clear(Color.Orange);
      }
   }
}

// And the HMDemo class...
using HMEngine.HMObjects;

class HMDemo {
   static HMGame game = new HMGame();
   static HMTestObject test = new HMTestObject();
   public static void Main() {
      game.Scene.AddObject(test);
      game.Run();
   }
}

The top part is a new class to create in the Engine.  The bottom part shows the code from the Demo.  The testobject class goes in the engine, but you create an instance of it in the demo to render on the scene.

If you haven't already, download some of the tutorial code samples from the forums here and take a look at it.  It still helps to go through the tutorials and follow through creating the code yourself for understanding, but the actual code is already written so you can check it if you're having problems.
Logged
Tyler
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #9 on: 2007/05/30 07:36:39 »

I got it to work Grin
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tut 6: Model Class Hazy Mind XNA Engine MicahN 2 2258 Last post 2006/11/15 09:43:47
by MicahN
Changing Sprite class texture coords? Hazy Mind XNA Engine Mithaearon 1 2029 Last post 2007/01/29 13:46:11
by h4rdc0m
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.139 seconds with 19 queries.