예제 #1
0
        /// <summary>
        /// Determines how the drawable is drawn to the screen.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch that this drawable will be drawn under.</param>
        /// <param name="parent">The parent drawable.  This value can be null if the drawable
        /// does not have a parent.</param>
        public void Draw(SpriteBatch spriteBatch, IDrawable parent)
        {
            float rotation = Rotation;

            if (parent != null)
            {
                rotation = parent.Rotation + Rotation;
            }

            Vector2 finalPosition = OrionMath.RotatePointPositive(Position, Vector2.Zero, rotation);

            finalPosition += parent.Position;

            if (_renderTarget != null)
            {
                spriteBatch.Draw(
                    _renderTarget,
                    finalPosition,
                    new Rectangle(0, 0, _renderTarget.Width, _renderTarget.Height),
                    Color.White,
                    (float)OrionMath.ToRadians(rotation),
                    new Vector2(_renderTarget.Width / 2, _renderTarget.Height / 2),
                    1.0f,
                    _spriteEffects,
                    0.0f
                    );
            }
        }
예제 #2
0
        public virtual void Draw(SpriteBatch spriteBatch, IDrawable parent)
        {
            float rotation = Rotation;

            if (parent != null)
            {
                rotation = parent.Rotation + Rotation;
            }

            Vector2 finalPosition = OrionMath.RotatePointPositive(Position, Vector2.Zero, rotation);

            if (parent != null)
            {
                finalPosition += parent.Position;
            }

            spriteBatch.Draw(
                Texture,
                finalPosition,
                _drawRect,
                new Color(Tint, Alpha),
                (float)OrionMath.ToRadians(rotation),
                Origin,
                Scale,
                SpriteEffects.None,
                0.0f
                );
        }
예제 #3
0
        public override void Update(GameTime gameTime, IUpdatable parent)
        {
            // When physics are enabled, entity movements are handled
            // by the physics engine.
            if (!_physicsFlag)
            {
                // calc speed as a scalar
                float speed = Velocity.Length();

                // update the position
                Position += new Vector2(
                    (float)Math.Cos(OrionMath.ToRadians(Rotation - 90.0f)) * speed * (float)gameTime.ElapsedGameTime.TotalSeconds,
                    (float)Math.Sin(OrionMath.ToRadians(Rotation - 90.0f)) * speed * (float)gameTime.ElapsedGameTime.TotalSeconds
                    );
            }

            base.Update(gameTime, parent);
        }
예제 #4
0
        /// <summary>
        /// Determines how the primative is drawn to the screen.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch that this drawable will be drawn under.</param>
        public void Draw(SpriteBatch spriteBatch, IDrawable parent)
        {
            int x = (int)(Position.X - Origin.X);
            int y = (int)(Position.Y - Origin.Y);

            Primitives2D.FillRectangle(
                spriteBatch,
                new Rectangle(x, y, Width, Height),
                FillColor,
                (float)OrionMath.ToRadians(Rotation)
                );

            Vector2 v1 = OrionMath.RotatePointPositive(new Vector2(x, y), Origin, Rotation);
            Vector2 v2 = OrionMath.RotatePointPositive(new Vector2(x + Width, y), Origin, Rotation);
            Vector2 v3 = OrionMath.RotatePointPositive(new Vector2(x + Width, y + Height), Origin, Rotation);
            Vector2 v4 = OrionMath.RotatePointPositive(new Vector2(x, y + Height), Origin, Rotation);

            Primitives2D.DrawLine(spriteBatch, v1, v2, BorderColor, BorderWidth);
            Primitives2D.DrawLine(spriteBatch, v2, v3, BorderColor, BorderWidth);
            Primitives2D.DrawLine(spriteBatch, v3, v4, BorderColor, BorderWidth);
            Primitives2D.DrawLine(spriteBatch, v4, v1, BorderColor, BorderWidth);
        }