Example #1
0
        //#if WINDOWS
        //        protected GameScene(SerializationInfo info, StreamingContext context)
        //        {
        //            if (info == null)
        //                throw new ArgumentNullException("info");

        //            foreach (SerializationEntry entry in info)
        //            {
        //                switch (entry.Name)
        //                {
        //                    case "name":
        //                        name = (string)entry.Value; break;
        //                    case "camera":
        //                        camera = (Camera)entry.Value; break;
        //                    case "gravity":
        //                        gravity = (Vector2)entry.Value; break;
        //                    case "backgroundColor":
        //                        backgroundColor = (Color)entry.Value; break;
        //                    case "gameObjects":
        //                        object obj = entry.Value;
        //                        if (obj.GetType().IsSubclassOf(typeof(System.Collections.CollectionBase)))
        //                        {
        //                            // handle old projects:
        //                            System.Collections.CollectionBase bx = (System.Collections.CollectionBase)obj;
        //                            this.gameObjects = new GameObjectCollection(null);
        //                            foreach (var ob in bx)
        //                            {
        //                                this.gameObjects.Add(ob as GameObject);
        //                            }
        //                        }
        //                        else
        //                        {
        //                            gameObjects = (GameObjectCollection)entry.Value;
        //                        }
        //                        break;
        //                }
        //            }
        //        }

        //        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
        //        public void GetObjectData(SerializationInfo info, StreamingContext context)
        //        {
        //            if (info == null)
        //                throw new ArgumentNullException("info");

        //            info.AddValue("name", name);
        //            info.AddValue("camera", camera);
        //            info.AddValue("backgroundColor", backgroundColor);
        //            info.AddValue("gravity", gravity);
        //            info.AddValue("gameObjects", gameObjects);
        //        }
        //#endif
        #endregion

        #region methods

        /// <summary>
        /// Initializes the Game Scene.
        /// The Layers, game objects and components of this scene are initialized too.
        /// </summary>
        public virtual void Initialize()
        {
            if (renderViews == null)
            {
                renderViews = new List <RenderView>();
            }

            if (CommonTags == null)
            {
                CommonTags = new List <string>();
            }

            markedForRemoval = new List <GameObject>();

            if (world != null)
            {
                //foreach (var obj in world.BodyList)
                //    world.RemoveBody(obj);

                //world.Step(0);
            }
            else
            {
                world = new World(gravity);
            }

            debugView = new DebugView2D(world);
            debugView.RemoveFlags(DebugViewFlags.Controllers);
            debugView.LoadContent(SceneManager.GraphicsDevice, Content);

            //if(SceneManager.IsEditor)
            //    debugView.Flags = DebugViewFlags.PerformanceGraph | DebugViewFlags.DebugPanel | DebugViewFlags.Joint | DebugViewFlags.Shape;

            foreach (GameObject obj in gameObjects)
            {
                obj.Initialize();
            }
        }
Example #2
0
        //#if WINDOWS
        //        protected GameScene(SerializationInfo info, StreamingContext context)
        //        {
        //            if (info == null)
        //                throw new ArgumentNullException("info");

        //            foreach (SerializationEntry entry in info)
        //            {
        //                switch (entry.Name)
        //                {
        //                    case "name":
        //                        name = (string)entry.Value; break;
        //                    case "camera":
        //                        camera = (Camera)entry.Value; break;
        //                    case "gravity":
        //                        gravity = (Vector2)entry.Value; break;
        //                    case "backgroundColor":
        //                        backgroundColor = (Color)entry.Value; break;
        //                    case "gameObjects":
        //                        object obj = entry.Value;
        //                        if (obj.GetType().IsSubclassOf(typeof(System.Collections.CollectionBase)))
        //                        {
        //                            // handle old projects:
        //                            System.Collections.CollectionBase bx = (System.Collections.CollectionBase)obj;
        //                            this.gameObjects = new GameObjectCollection(null);
        //                            foreach (var ob in bx)
        //                            {
        //                                this.gameObjects.Add(ob as GameObject);
        //                            }
        //                        }
        //                        else
        //                        {
        //                            gameObjects = (GameObjectCollection)entry.Value;
        //                        }
        //                        break;
        //                }
        //            }
        //        }

        //        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
        //        public void GetObjectData(SerializationInfo info, StreamingContext context)
        //        {
        //            if (info == null)
        //                throw new ArgumentNullException("info");

        //            info.AddValue("name", name);
        //            info.AddValue("camera", camera);
        //            info.AddValue("backgroundColor", backgroundColor);
        //            info.AddValue("gravity", gravity);
        //            info.AddValue("gameObjects", gameObjects);
        //        }
        //#endif
        #endregion

        #region methods

        /// <summary>
        /// Initializes the Game Scene.
        /// The Layers, game objects and components of this scene are initialized too.
        /// </summary>
        public virtual void Initialize()
        {
            if (renderViews == null)
                renderViews = new List<RenderView>();

            if (CommonTags == null)
                CommonTags = new List<string>();

            markedForRemoval = new List<GameObject>();

            if (world != null)
            {
                //foreach (var obj in world.BodyList)
                //    world.RemoveBody(obj);

                //world.Step(0);
            }
            else
            {
                world = new World(gravity);
            }

            debugView = new DebugView2D(world);
            debugView.RemoveFlags(DebugViewFlags.Controllers);
            debugView.LoadContent(SceneManager.GraphicsDevice, Content);

            //if(SceneManager.IsEditor)
            //    debugView.Flags = DebugViewFlags.PerformanceGraph | DebugViewFlags.DebugPanel | DebugViewFlags.Joint | DebugViewFlags.Shape;

            foreach (GameObject obj in gameObjects)
                obj.Initialize();
        }