Example #1
0
        public ActorViewer(Room parentRoom, Vector2 size, Color backgroundColor) : base(parentRoom)
        {
            this.backgroundColor = backgroundColor;

            Size           = size;
            backgroundSize = new Vector2(DisplayRect().Size.X, DisplayRect().Size.Y);
            renderTarget   = new RenderTarget2D(Game1.ActiveGame.GraphicsDevice, (int)backgroundSize.X, (int)backgroundSize.Y);
            SpriteImage    = new Sprite(renderTarget, renderTarget.GetRectangle());

            cubesPadding = 1;
        }
Example #2
0
        public void ResetActor()
        {
            if (renderTarget != null)
            {
                renderTarget.Dispose();
                renderTarget = null;
            }

            renderTarget = new RenderTarget2D(Game1.ActiveGame.GraphicsDevice, (int)backgroundSize.X, (int)backgroundSize.Y);
            SpriteImage  = new Sprite(renderTarget, renderTarget.GetRectangle());
            actor        = null;
            actorDrawn   = false;
        }
        public override void Prepare(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            if (dynamicBackground != null && dynamicBackgroundChanged)
            {
                var backgroundTarget = new RenderTarget2D(graphicsDevice, (int)Size.X, (int)Size.Y);
                var pieceSizeX       = dynamicBackground.SourceRectangle.Width / 3;
                var pieceSizeY       = dynamicBackground.SourceRectangle.Height / 3;
                var realPieceSizeX   = pieceSizeX * dynamicBackgroundScale;
                var realPieceSizeY   = pieceSizeY * dynamicBackgroundScale;

                graphicsDevice.SetRenderTarget(backgroundTarget);
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp);
                graphicsDevice.DepthStencilState = new DepthStencilState()
                {
                    DepthBufferEnable = true
                };
                graphicsDevice.Clear(Color.Transparent);

                for (int x = 0; x < 3; x++)
                {
                    for (int y = 0; y < 3; y++)
                    {
                        var resultWidth  = x != 1 ? realPieceSizeX : (int)(Size.X - 2 * realPieceSizeX);
                        var resultHeigth = y != 1 ? realPieceSizeY : (int)(Size.Y - 2 * realPieceSizeY);
                        var resultX      = x != 2 ? realPieceSizeX * x : (int)(Size.X - realPieceSizeX);
                        var resultY      = y != 2 ? realPieceSizeY * y : (int)(Size.Y - realPieceSizeY);


                        spriteBatch.Draw(dynamicBackground.TextureRef, new Rectangle(resultX, resultY, resultWidth, resultHeigth), new Rectangle(dynamicBackground.SourceRectangle.X + pieceSizeX * x, dynamicBackground.SourceRectangle.Y + pieceSizeY * y, pieceSizeX, pieceSizeY), Color.White);
                    }
                }

                spriteBatch.End();
                graphicsDevice.SetRenderTarget(null);

                SpriteImage = new Sprite(backgroundTarget, backgroundTarget.GetRectangle());
                dynamicBackgroundChanged = false;
            }

            base.Prepare(spriteBatch, graphicsDevice);
        }
Example #4
0
        public override void Prepare(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            if (IsPaused)
            {
                return;
            }

            if (backgroundChanged)
            {
                if (backgroundRenderTarget == null || backgroundRenderTarget.IsContentLost || backgroundRenderTarget.IsDisposed)
                {
                    if (backgroundRenderTarget != null)
                    {
                        backgroundRenderTarget.Dispose();
                        backgroundRenderTarget = null;
                    }

                    backgroundRenderTarget = new RenderTarget2D(Game1.ActiveGame.GraphicsDevice, (int)backgroundSize.X, (int)backgroundSize.Y);
                }

                graphicsDevice.SetRenderTarget(backgroundRenderTarget);
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
                graphicsDevice.DepthStencilState = new DepthStencilState()
                {
                    DepthBufferEnable = true
                };
                graphicsDevice.Clear(BorderColor);

                spriteBatch.Draw(
                    Contents.Sprites.Pix.TextureRef,
                    new Rectangle(playgroundInnerPadding - 2 * playgroundCubeMargin, playgroundInnerPadding - 2 * playgroundCubeMargin, (int)backgroundSize.X - 2 * (playgroundInnerPadding - 2 * playgroundCubeMargin), (int)backgroundSize.Y - 2 * (playgroundInnerPadding - 2 * playgroundCubeMargin)),
                    Contents.Sprites.Pix.SourceRectangle,
                    BackgroundColor);

                for (int x = 0; x < playground.GetLength(0); x++)
                {
                    for (int y = 0; y < playground.GetLength(1); y++)
                    {
                        spriteBatch.Draw(
                            Contents.Sprites.Pix.TextureRef,
                            new Rectangle(playgroundInnerPadding + x * (playgroundCubeSize + playgroundCubeMargin), playgroundInnerPadding + y * (playgroundCubeSize + playgroundCubeMargin), playgroundCubeSize, playgroundCubeSize),
                            Contents.Sprites.Pix.SourceRectangle,
                            GetCubeColor(x, y));
                    }
                }

                spriteBatch.End();
                graphicsDevice.SetRenderTarget(null);
                backgroundChanged = false;
            }

            if (mainRenderTarget == null || mainRenderTarget.IsContentLost || mainRenderTarget.IsDisposed)
            {
                if (mainRenderTarget != null)
                {
                    mainRenderTarget.Dispose();
                    mainRenderTarget = null;
                }

                mainRenderTarget = new RenderTarget2D(Game1.ActiveGame.GraphicsDevice, (int)backgroundSize.X, (int)backgroundSize.Y);
                SpriteImage      = new Sprite(mainRenderTarget, mainRenderTarget.GetRectangle());
            }

            graphicsDevice.SetRenderTarget(mainRenderTarget);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            graphicsDevice.Clear(Color.Transparent);

            spriteBatch.Draw(
                backgroundRenderTarget,
                new Rectangle(0, 0, (int)backgroundSize.X, (int)backgroundSize.Y),
                Color.White);

            foreach (var effect in playgroundEffectsList)
            {
                spriteBatch.Draw(
                    Contents.Sprites.Pix.TextureRef,
                    new Rectangle(playgroundInnerPadding + effect.Item1 * (playgroundCubeSize + playgroundCubeMargin), playgroundInnerPadding + effect.Item2 * (playgroundCubeSize + playgroundCubeMargin), playgroundCubeSize, playgroundCubeSize),
                    Contents.Sprites.Pix.SourceRectangle,
                    effect.Item3);
            }

            spriteBatch.End();
            graphicsDevice.SetRenderTarget(null);
        }