Example #1
0
        /// <summary>
        /// Creates the visual elements of the game and adds them to game Components.
        /// </summary>
        private void PopulateGame()
        {
            int drawOrder = 0;

            // Create the background Canvas and add it to game Components
            meshCanvas = new MeshCanvas(
                this,
                controller,
                @"Content\ApplicationBackground.jpg",
                graphics.PreferredBackBufferWidth * 2,
                graphics.PreferredBackBufferHeight * 2);
            meshCanvas.Name = "meshCanvas";
            meshCanvas.DrawOrder = drawOrder++;
            meshCanvas.AutoScaleTexture = false;
            meshCanvas.SpriteBlendState = BlendState.NonPremultiplied;

            Components.Add(meshCanvas);

            // Created the UIElement that encapsulates the cloth simulation component.
            textiles = new Textiles(this, controller);

            // Once we created the textiles, we can enable the tap gesture.
            touchTarget.TouchTapGesture += OnTouchTapGesture;

            textiles.DrawOrder = drawOrder++;

            // Create the HUD Container and add it to game Components
            hudContainer = new UIContainer(
                this,
                controller,
                @"Content\Transparent256x256.png",
                null,
                256,
                256,
                null);
            hudContainer.Name = "hudContainer";
            hudContainer.Center = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f,
                                    graphics.GraphicsDevice.Viewport.Height / 2f);
            hudContainer.DrawOrder = drawOrder++;
            hudContainer.LayerDepth = 1.0f;
            hudContainer.SpriteBlendState = BlendState.NonPremultiplied;
            hudContainer.Active = false;

            Components.Add(hudContainer);

            // Create and position listbox and add it to the hudCanvas.
            Vector2 position = new Vector2(0f, 0f);
            listbox = new UI.ListBox(
                hudContainer,
                position,
                3 * UI.ListBox.ItemWidth,
                UI.ListBox.ItemHeight,
                textiles);
            listbox.Name = "listbox";
            listbox.AutoScaleTexture = false;
        }
Example #2
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    IDisposable graphicsDispose = graphics as IDisposable;
                    if (graphicsDispose != null)
                    {
                        graphicsDispose.Dispose();
                    }

                    if (touchTarget != null)
                    {
                        touchTarget.Dispose();
                        touchTarget = null;
                    }
                    if (textiles != null)
                    {
                        textiles.Dispose();
                        textiles = null;
                    }
                    if (hudContainer != null)
                    {
                        hudContainer.Dispose();
                        hudContainer = null;
                    }
                    if (listbox != null)
                    {
                        listbox.Dispose();
                        listbox = null;
                    }
                    if (meshCanvas != null)
                    {
                        meshCanvas.Dispose();
                        meshCanvas = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }