Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualsatsujin

Posted 12 November 2013 - 04:33 AM

Here is the code I have in Game1.cs:

namespace Reflection
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableGameComponent room;
        GameComponentCollection complist;
        GameTime gt;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            room = new Level1(this);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
            
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void ChangeScreen(DrawableGameComponent curroom, Type type)
        {
            room = (DrawableGameComponent)Activator.CreateInstance(type,this);
            this.Components.Remove(curroom);
            this.Components.Add(room);
            //room.Draw(gt);
        }
    }
}

Then, the modified DrawableGameComponent class in Level1.cs:

   public class Level1 : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game;
        public Level1(Game1 game): base(game)
        {
            this.game = game;
        }

       public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            game.ChangeScreen(this, Type.GetType("Reflection.Level2"));
            base.Update(gameTime);
        }

And the screen color changing code in DrawableGameComponet class Level2.cs:

       public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Red);
            base.Draw(gameTime);
        }

I want this code to initially load the room Level1 class in Game1 which then immediately changes the screen  to Level2 . However, it only seems to run the Update and Draw loops in Game1. I want the DrawableGameComponent room variable to load the component specified in it and then loop that component's Update and Draw functions until changeScreen is called for new component(room) again. Each time only one room should be displayed but each room should be able to store multiple sub-components of sprites etc. That way you could set a current room to loop with its eventhandlers and sprites until a new room need to be load after exiting the current one.


#5satsujin

Posted 12 November 2013 - 04:17 AM

Here is the code I have in Game1.cs:

namespace Reflection
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableGameComponent room;
        GameComponentCollection complist;
        GameTime gt;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            room = new Level1(this);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
            
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void ChangeScreen(DrawableGameComponent curroom, Type type)
        {
            room = null;
            room = (DrawableGameComponent)Activator.CreateInstance(type);
            this.Components.Add(room);
            //room.Draw(gt);
        }
    }
}

Then, the modified DrawableGameComponent class in Level1.cs:

   public class Level1 : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game;
        public Level1(Game1 game): base(game)
        {
            this.game = game;
        }

       public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            game.ChangeScreen(this, Type.GetType("Reflection.Level2"));
            base.Update(gameTime);
        }

And the screen color changing code in DrawableGameComponet class Level2.cs:

       public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Red);
            base.Draw(gameTime);
        }

I want this code to initially load the room Level1 class in Game1 which then immediately changes the screen  to Level2 . However, it only seems to run the Update and Draw loops in Game1. I want the DrawableGameComponent room variable to load the component specified in it and then loop that component's Update and Draw functions until changeScreen is called for new component(room) again. Each time only one room should be displayed but each room should be able to store multiple sub-components of sprites etc. That way you could set a current room to loop with its eventhandlers and sprites until a new room need to be load after exiting the current one.


#4satsujin

Posted 12 November 2013 - 04:13 AM

Here is the code I have in Game1.cs:

namespace Reflection
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableGameComponent room;
        GameComponentCollection complist;
        GameTime gt;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            room = new Level1(this);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
            
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void ChangeScreen(DrawableGameComponent curroom, Type type)
        {
            room = null;
            room = (DrawableGameComponent)Activator.CreateInstance(type);
            this.Components.Add(room);
            //room.Draw(gt);
        }
    }
}

Then, the modified DrawableGameComponent class in Level1.cs:

   public class Level1 : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game;
        public Level1(Game1 game): base(game)
        {
            this.game = game;
        }

       public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            game.ChangeScreen(this, Type.GetType("Reflection.Level2"));
            base.Update(gameTime);
        }

And the screen color changing code in DrawableGameComponet class Level2.cs:

       public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Red);
            base.Draw(gameTime);
        }

I want this code to initially load the room Level1 class in Game1 which then immediately changes the screen  to Level2 . However, it only seems to run the Update and Draw loops in Game1. I want the DrawableGameComponent room variable to load the component specified in it and then loop that component's Update and Draw functions until changeScreen is called for new component(room) again. Each time only one room should be displayed but each room should be able to store multiple sub-components of sprites etc.


#3satsujin

Posted 11 November 2013 - 11:47 PM

Here is the code I have in Game1.cs:

namespace Reflection
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableGameComponent room;
        GameComponentCollection complist;
        GameTime gt;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            room = new Level1(this);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
            
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void ChangeScreen(DrawableGameComponent curroom, Type type)
        {
            room = null;
            room = (DrawableGameComponent)Activator.CreateInstance(type);
            this.Components.Add(room);
            //room.Draw(gt);
        }
    }
}

Then, the modified DrawableGameComponent class in Level1.cs:

   public class Level1 : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game;
        public Level1(Game1 game): base(game)
        {
            this.game = game;
        }

       public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            game.ChangeScreen(this, Type.GetType("Reflection.Level2"));
            base.Update(gameTime);
        }

And the screen color changing code in DrawableGameComponet class Level2.cs:

       public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Red);
            base.Draw(gameTime);
        }

I want this code to initially load the room Level1 class in Game1 which then immediately changes the screen  to Level2 . However, it only seems to run the Update and Draw loops in Game1. I want the DrawableGameComponent room variable to load the component specified in it and then loop that component's Update and Draw functions until changeScreen is called for new component again.


#2satsujin

Posted 11 November 2013 - 11:45 PM

Here is the code I have in Game1.cs:

namespace Reflection
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableGameComponent room;
        GameComponentCollection complist;
        GameTime gt;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            room = new Level1(this);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
            
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void ChangeScreen(DrawableGameComponent curroom, Type type)
        {
            room = null;
            room = (DrawableGameComponent)Activator.CreateInstance(type);
            this.Components.Add(room);
            //room.Draw(gt);
        }
    }
}

Then, the modified DrawableGameComponent class in Level1.cs:

   public class Level1 : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game;
        public Level1(Game1 game): base(game)
        {
            this.game = game;
        }

       public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            game.ChangeScreen(this, Type.GetType("Reflection.Level2"));
            base.Update(gameTime);
        }

And the screen color changing code in DrawableGameComponet class Level2.cs:

       public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Red);
            base.Draw(gameTime);
        }

I want this code to initially load the room Level1 class in Game1 which then immediately changes the screen  to Level2 . However, it only seems to run the Update and Draw loops in Game1. I want the DrawableGameComponent room variable to load the component specified in it and then loop that component's Update and Draw functions until changeScreen is called for new component again. It currently only seems to loop the Draw function in Game1.


#1satsujin

Posted 11 November 2013 - 11:44 PM

Here is the code I have in Game1.cs:

namespace Reflection
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableGameComponent room;
        GameComponentCollection complist;
        GameTime gt;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            room = new Level1(this);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
            
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void ChangeScreen(DrawableGameComponent curroom, Type type)
        {
            room = null;
            room = (DrawableGameComponent)Activator.CreateInstance(type);
            this.Components.Add(room);
            //room.Draw(gt);
        }
    }
}

Then, the modified DrawableGameComponent class in Level1.cs:

   public class Level1 : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game;
        public Level1(Game1 game): base(game)
        {
            this.game = game;
        }

       public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            game.ChangeScreen(this, Type.GetType("Reflection.Level2"));
            base.Update(gameTime);
        }

And the screen color changing code in DrawableGameComponet class Level2.cs:

       public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Red);
            base.Draw(gameTime);
        }

I want this code to initially load the room Level1 class in Game1 which then immediately changes the screen  to Level2 . However, it only seems to run the Update and Draw loops in Game1. I want the DrawableGameComponent room variable to load the component specified in it and then loop that component's Update and Draw functions until changeScreen is called for new component again.


PARTNERS