protected override void Draw()
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            // Use SpriteSortMode.Immediate, so we can apply custom renderstates.
            _spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
                               SpriteSortMode.Immediate,
                               SaveStateMode.SaveState);

            // Set the texture addressing mode to wrap, so we can repeat
            // many copies of our tiled checkerboard texture.
            GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
            Rectangle fullRect = new Rectangle(0, 0, this.Width, this.Height);

            // Draw a tiled checkerboard pattern in the background.
            _spriteBatch.Draw(_crossTexture, fullRect, fullRect, Color.White);
            if (SceneItem == null)
            {
                _spriteBatch.End();
            }
            else
            {
                _spriteBatch.End();
                DrawingManager.ViewPortSize = new Point(this.Width, this.Height);
                _camera.Position            = Vector2.Zero;
                _camera.Update(1 / 60f);
                Vector2 oldPivot           = SceneItem.Pivot;
                bool    oldIsPivotRelative = SceneItem.IsPivotRelative;
                Vector2 oldPosition        = SceneItem.Position;
                float   oldRotation        = SceneItem.Rotation;
                Vector2 oldScale           = SceneItem.Scale;
                bool    oldVisibility      = SceneItem.Visible;
                SceneItem.Visible         = true;
                SceneItem.Position        = Vector2.Zero;
                SceneItem.Pivot           = new Vector2(0.5f);
                SceneItem.IsPivotRelative = true;
                SceneItem.Scale           = Vector2.One;
                SceneItem.Rotation        = 0;
                SceneItem.Update(1 / 60f);
                SceneItem.Draw(1 / 60f);
                SceneItem.Position        = oldPosition;
                SceneItem.Pivot           = oldPivot;
                SceneItem.IsPivotRelative = oldIsPivotRelative;
                SceneItem.Scale           = oldScale;
                SceneItem.Rotation        = oldRotation;
                SceneItem.Visible         = oldVisibility;
                MilkshakeForm.SwapCameraAndRenderScene(_camera);
            }
        }
Ejemplo n.º 2
0
        public void Draw(float elapsed)
        {
            if (Parent == null)
            {
                throw new Exception("The Parent of this boneTransform isn't set");
            }
            SceneItem item = GetSceneItem();

            if (item != null)
            {
                if (_currentVisibleState == true)
                {
                    CompositeEntity parentEntity     = Parent.Parent.Parent;
                    Vector2         tmpPivot         = item.Pivot;
                    bool            tmpPivotRelative = item.IsPivotRelative;
                    item.Rotation = parentEntity.Rotation + _rotation;
                    item.Scale    = parentEntity.Scale * _scale;
                    item.Visible  = true;
                    item.Position = parentEntity.Position + _position;
                    float parentOpacityFactor = parentEntity.Opacity / 255.0f;
                    if (_opacity.HasValue)
                    {
                        item.Opacity = (byte)(_opacity.Value * parentOpacityFactor);
                    }
                    else
                    {
                        item.Opacity = parentEntity.Opacity;
                    }
                    item.Layer           = parentEntity.Layer;
                    item.Pivot           = _transformPivot;
                    item.IsPivotRelative = false;
                    item.Draw(elapsed);
                    item.Pivot           = tmpPivot;
                    item.IsPivotRelative = tmpPivotRelative;
                }
                else
                {
                    item.Visible = false;
                }
            }
        }