public SpriteRenderer(Entity parent)
     : base(parent)
 {
     this.Color = Color.White;
     this.Scale = 1;
     this.SpriteEffects = SpriteEffects.None;
 }
Example #2
1
        public Human(Game game, SpriteBatch screenSpriteBatch,
            PlayerSide playerSide)
            : base(game, screenSpriteBatch)
        {
            string idleTextureName = "";
            this.playerSide = playerSide;

            if (playerSide == PlayerSide.Left)
            {
                catapultPosition = new Vector2(140, 332);
                idleTextureName = "Textures/Catapults/Blue/blueIdle/blueIdle";
            }
            else
            {
                catapultPosition = new Vector2(600, 332);
                spriteEffect = SpriteEffects.FlipHorizontally;
                idleTextureName = "Textures/Catapults/Red/redIdle/redIdle";
            }

            Catapult = new Catapult(game, screenSpriteBatch,
                                    idleTextureName, catapultPosition,
                                    spriteEffect,
                                    playerSide == PlayerSide.Left
                                        ? false : true, true);
        }
 public SpritePresentationInfo(Rectangle sourceRectangle, float layerDepth)
 {
     this.sourceRectangle = sourceRectangle;
     this.layerDepth = layerDepth;
     this.color = Color.White;
     this.effect = SpriteEffects.None;
 }
Example #4
0
        protected void goToET()
        {
            if (et_pos != null)
            {
                if (et_pos.X > pos.X)
                {
                    foeEffect = SpriteEffects.None;
                    pos.X++;
                }
                else
                {
                    foeEffect = SpriteEffects.FlipHorizontally;
                    pos.X--;
                }

                if (et_pos.Y > pos.Y)
                {
                    pos.Y++;
                }
                else
                {
                    pos.Y--;
                }
            }
        }
 public Graphic(Texture2D texture)
 {
     this.texture = texture;
     this.mode = Mode.Sprite;
     this.rotation = 0.0f;
     this.effect = SpriteEffects.None;
 }
Example #6
0
 public GameObject(Game1 game, Vector2 startLocation)
 {
     this.Game = game;
     this.Location = startLocation;
     this.Transparency = 1;
     SpriteEffect = SpriteEffects.None;
 }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects)
        {
            if (Animation == null)
            {
                throw new NotSupportedException("No animation is currently playing.");
            }

            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.frameTime)
            {
                time -= Animation.frameTime;

                if (Animation.isLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;

                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }

            Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0, Animation.FrameWidth, Animation.FrameHeight);

            spriteBatch.Draw(animation.texture, position, source, Color.White, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.0f);
        }
Example #8
0
        /// <summary>
        /// Advances the time position and draws the current frame of the animation.
        /// </summary>
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects)
        {
            if (Animation == null)
                throw new NotSupportedException("No animation is currently playing.");

            // Process passing time.
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.FrameTime)
            {
                time -= Animation.FrameTime;

                // Advance the frame index; looping or clamping as appropriate.
                if (Animation.IsLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;
                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }

            // Calculate the source rectangle of the current frame.
            Rectangle source = new Rectangle(FrameIndex * Animation.Texture.Height, 0, Animation.Texture.Width/Animation.FrameCount, Animation.Texture.Height);

            // Draw the current frame.
            spriteBatch.Draw(Animation.Texture, position, source, Color.White, 0.0f, Origin, 1.0f, spriteEffects, 0.0f);
        }
 // De constructor
 public AnimatedSprite(IAnimatedSprite iAnimatedSprite)
 {
     this.iAnimatedSprite = iAnimatedSprite;
     this.sourceRectangle = new Rectangle(this.imageNumber * 32, 0, 32, 32);
     this.effect = SpriteEffects.None;
     this.pivot = new Vector2(16f, 16f);
 }
 public AnimatedSprite(iAnimatedSprite iAnimatedSprite)
 {
     this.iAnimatedSprite = iAnimatedSprite;
     this.sourceRectangle = new Rectangle(0, 0, 32, 32);
     this.effect = SpriteEffects.None;
     this.pivot = new Vector2(16f, 16);
 }
Example #11
0
        // <param name="position">This should be where you want the pivot point of the sprite image to be rendered.</param>
        public void Draw(SpriteFrame sprite, Vector2 position, Color? color = null, float rotation = 0, float scale = 1, SpriteEffects spriteEffects = SpriteEffects.None)
        {
            Vector2 origin = sprite.Origin;
            if (sprite.IsRotated)
            {
                rotation -= ClockwiseNinetyDegreeRotation;
                switch (spriteEffects)
                {
                    case SpriteEffects.FlipHorizontally: spriteEffects = SpriteEffects.FlipVertically; break;
                    case SpriteEffects.FlipVertically: spriteEffects = SpriteEffects.FlipHorizontally; break;
                }
            }
            switch (spriteEffects)
            {
                case SpriteEffects.FlipHorizontally: origin.X = sprite.SourceRectangle.Width - origin.X; break;
                case SpriteEffects.FlipVertically: origin.Y = sprite.SourceRectangle.Height - origin.Y; break;
            }

            this.spriteBatch.Draw(
                texture: sprite.Texture,
                position: position,
                sourceRectangle: sprite.SourceRectangle,
                color: color,
                rotation: rotation,
                origin: origin,
                scale: new Vector2(scale, scale),
                effects: spriteEffects);
        }
Example #12
0
        public Robot(ADHDGame g, Stage st)
        {
            //init anims
            right = new Animation(new Rectangle(0, 206, Size.X, Size.Y), 9, rate, true);
            up = new Animation(new Rectangle(0, 103, Size.X, Size.Y), 9, rate, true);
            down = new Animation(new Rectangle(0, 0, Size.X, Size.Y), 9, rate, true);
            banjo = new Animation(new Rectangle(0, 618, Size.X, Size.Y), 9, 1.0f / 10.0f, false);
            banjoPlay = new Animation(new Rectangle(0, 721, Size.X, Size.Y), 9, 1.0f / 10.0f, true);
            die = new Animation(new Rectangle(0, 824, Size.X, Size.Y), 9, 1.0f / 10.0f, false);
            pushDown = new Animation(new Rectangle(0, 309, Size.X, Size.Y), 9, 1.0f / 20.0f, false);
            pushUp = new Animation(new Rectangle(0, 412, Size.X, Size.Y), 9, 1.0f / 20.0f, false);
            pushRight = new Animation(new Rectangle(0, 515, Size.X, Size.Y), 9, 1.0f / 20.0f, false);

            tex = g.Content.Load<Texture2D>("robot");
            batch = st.batch;
            stage = st;
            position = Stage.TileToPos(new Point(11, 17));
            currAnim = down;
            currAnim.Stop();
            Dir = Direction.Down;
            velocity = Vector2.Zero;
            flip = SpriteEffects.None;
            game = g;
            SnapToTile();
        }
Example #13
0
        public Gun(Texture2D[] inputTexture, SoundEffect inputZap)
        {
            // Gun's textures.
            textureHolding = inputTexture;
            gunTexture = inputTexture[0];
            borderTexture = inputTexture[2];
            // Munitions-in-flight.
            BULLETS = new List<Bullet>();
            // Offset for animation rotation.
            rotationOffset = new Vector2(17.5F, 9);
            // Width and height of the gun's sprite.
            frameWidth = 35;
            frameHeight = 18;
            // Color, rotation, and effects.
            color = Color.White;
            rotation = 0;
            effects = SpriteEffects.None;
            // Where do you want the gun placed relative to the vector it is attached too?
            placementXOffset = 15;
            placementYOffset = 35;
            // Zap sound effect.
            zap = inputZap;
            animationFrame = new Rectangle(0, 0, frameWidth, frameHeight);

            mineSpawn = new Stopwatch();
        }
Example #14
0
        public void Advance(Position position__1, SpriteEffects flip)
        {
            if (flip == SpriteEffects.FlipHorizontally)
            {
            this.flip = SpriteEffects.None;
            }
            else
            {
            this.flip = SpriteEffects.FlipHorizontally;
            }

            if (position__1.X + SPRITE_SIZE_X - 30 <= Position.X)
            {
            //flip = SpriteEffects.None;
            spriteState.Add(Enumeration.State.advance, Enumeration.PriorityState.Normal);
            }
            else if (position__1.X - SPRITE_SIZE_X + 30 >= Position.X)
            {
            spriteState.Add(Enumeration.State.advance, Enumeration.PriorityState.Normal);
            }
            else
            {
            //flip = SpriteEffects.FlipHorizontally;
            Strike();
            //spriteState.Add(Enumeration.State.ready, Enumeration.PriorityState.Normal);
            return;
            }

            sprite.PlayAnimation(spriteSequence, spriteState.Value());
        }
Example #15
0
        /// <summary>
        /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground and background, setting the ignore properties if needed.
        /// </summary>
        /// <param name="value">The current string.</param>
        /// <param name="foreground">The foreground color. If null, <see cref="ColoredString.IgnoreForeground"/> will be set.</param>
        /// <param name="background">The background color. If null, <see cref="ColoredString.IgnoreBackground"/> will be set.</param>
        /// <param name="spriteEffect">The background color. If null, <see cref="ColoredString.IgnoreEffect"/> will be set.</param>
        /// <returns>A <see cref="ColoredString"/> object instace.</returns>
        public static ColoredString CreateColored(this string value, Color? foreground = null, Color? background = null, SpriteEffects? spriteEffect = null)
        {
            var stacks = new ParseCommandStacks();

            if (foreground.HasValue)
                stacks.AddSafe(new ParseCommandRecolor() { R = foreground.Value.R, G = foreground.Value.G, B = foreground.Value.B, A = foreground.Value.A, CommandType = CommandTypes.Foreground });

            if (background.HasValue)
                stacks.AddSafe(new ParseCommandRecolor() { R = background.Value.R, G = background.Value.G, B = background.Value.B, A = background.Value.A, CommandType = CommandTypes.Background });

            if (spriteEffect.HasValue)
                stacks.AddSafe(new ParseCommandSpriteEffect() { Effect = spriteEffect.Value, CommandType = CommandTypes.SpriteEffect });

            ColoredString newString = ColoredString.Parse(value, initialBehaviors: stacks);

            if (!foreground.HasValue)
                newString.IgnoreForeground = true;

            if (!background.HasValue)
                newString.IgnoreBackground = true;

            if (!spriteEffect.HasValue)
                newString.IgnoreSpriteEffect = true;

            return newString;
        }
Example #16
0
        //Constructor
        public Fireball(ContentManager content, Vector2 position, int direction, MouseState ms)
        {
            this.texture = content.Load<Texture2D>(@"pictures\Fireball");
            sound = content.Load<SoundEffect>(@"music\shotgun");
            Fireball.Sound.Play(0.5f, 0.0f, 0.0f);

            if (direction == 1)
            {
                this.position = position + new Vector2(80f, 60f);
                Vector2 speed = this.CalculateSpeed(this.position, ms);
                this.speed = new Vector2(this.maxSpeed * speed.X,
                                         this.maxSpeed * speed.Y);
                this.effect = SpriteEffects.None;
            }
            else
            {
                this.position = position + new Vector2(0f, 60f);
                Vector2 speed = this.CalculateSpeed(this.position, ms);
                this.speed = new Vector2(-this.maxSpeed * speed.X,
                                         -this.maxSpeed * speed.Y);
                this.effect = SpriteEffects.FlipHorizontally;
            }
            this.destinationRect = new Rectangle((int)this.position.X, (int)this.position.Y, 25, 24);
            this.sourceRect = new Rectangle(0, 0, 50, 48);
        }
 public UITextObject(string id, ObjectType objectType, Transform2D transform,
     Color color, SpriteEffects spriteEffects, float layerDepth, string text, SpriteFont spriteFont, bool isVisible)
     : base(id, objectType, transform, color, spriteEffects, layerDepth, isVisible)
 {
     this.spriteFont = spriteFont;
     this.text = text;
 }
Example #18
0
 /// <summary>
 /// Draws the specified texture2D, assuming that it was drawn assuming the screen is
 /// exactly 1920 * 1080. Be sure to call spriteBatch.Begin() before this and spriteBatch.End()
 /// at the end of the series of Drawing calls.
 /// </summary>
 /// <param name="texture2D">The texture2D.</param>
 /// <param name="position">The position.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="color">The color.</param>
 /// <param name="rotation">The rotation.</param>
 /// <param name="origin">The origin.</param>
 /// <param name="scale">The scale.</param>
 /// <param name="effects">The effects.</param>
 /// <param name="layerDepth">The layer depth.</param>
 public static void Draw(
     Texture2D texture2D,
     Vector2 position,
     Rectangle? sourceRectangle,
     Color color,
     float rotation,
     Vector2 origin,
     Vector2 scale,
     SpriteEffects effects,
     float layerDepth)
 {
     if (GameWorld.spriteBatch != null)
     {
         GameWorld.spriteBatch.Draw(
             texture2D,
             position * GetRatio(),
             sourceRectangle,
             color,
             rotation,
             origin,
             scale * GetRatio(),
             effects,
             layerDepth);
     }
 }
 public PoulpiMexico(Vector2 loc, Vector2 scroll, Bonus bonus, MovePattern pattern, SpriteEffects flip, String[] flags)
     : base(loc, scroll, bonus, pattern, flip,flags)
 {
     this.sRect = new Rectangle(0, 0, 320, 320);
     this.dRect = ComputeDstRect(sRect);
     this.spriteBox = new Vector2(320, 320);
 }
Example #20
0
 public void DrawLines(Batch Batch, Color? Color = null, float Size = 1,
     SpriteEffects Effect = SpriteEffects.None, float Layer = 0)
 {
     for (uint i = 0; i < Rays.Length; i++)
         if (Rays[i] != null)
             Rays[i].Draw(Batch, (Color ?? Microsoft.Xna.Framework.Color.White), Size, Effect, Layer);
 }
Example #21
0
        //public virtual Vector2 Bounds { get; set; }
        public override void ParseXml(XmlParser xp, string path)
        {
            base.ParseXml(xp, path);

            string rootnode = path + "->" + Name;
            Color = xp.GetColor(rootnode + "->Color", Color);
            Alpha = xp.GetFloat(rootnode + "->Alpha", Alpha);
            Scale = xp.GetVector2(rootnode + "->Scale", Scale);
            Layer = xp.GetFloat(rootnode + "->Layer", Layer);

            if(xp.CheckElement(rootnode + "->Flip"))
            {
                string s = xp.GetString(rootnode + "->Flip", "None");
                switch (s)
                {
                    case "None":
                        Flip = SpriteEffects.None;
                        break;
                    case "FlipH":
                        Flip = SpriteEffects.FlipHorizontally;
                        break;
                    case "FlipV":
                        Flip = SpriteEffects.FlipVertically;
                        break;
                }
            }
        }
 public UIMouseObject(string id, ObjectType objectType, Transform2D transform,
 Color color, SpriteEffects spriteEffects, float layerDepth, Texture2D texture, bool isVisible)
     : this(id, objectType, transform, color, spriteEffects, layerDepth, texture, 
         new Rectangle(0, 0, texture.Width, texture.Height),
             new Vector2(texture.Width / 2.0f, texture.Height / 2.0f), isVisible)
 {
 }
 public musicToggleButton(String artName, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color, float rotation,
     Vector2 origin, SpriteEffects effects, float layerDepth, Game game)
     : base(artName, destinationRectangle, sourceRectangle, color, rotation, origin, effects, layerDepth)
 {
     //Henter audiomanager fra game
     _audioManager = (IManageAudio)(game.Services.GetService(typeof(IManageAudio)));
 }
        //30sec ttl
        /// <summary>
        /// Super constructor for enemies. You must call it in subclasses
        /// </summary>
        /// <param name="_location">Screen location</param>
        /// <param name="_pattern">Move pattern to use</param>
        /// <param name="_scrollValue">Scroll value trigger</param>
        /// <param name="flags">Flags to set on death</param>
        /// <param name="flip">Type of flip</param>
        /// <param name="scale">Sprite scaling (use Vector2.One if not necessary)</param>
        /// <param name="speed">Speed of the enemy</param>
        /// <param name="spriteSrc">Spritesheet rectangle selection</param>
        /// <param name="_bonusDroppedOnDeath">Bonus the enemy will drop on death</param>
        /// <param name="weapon">Enemy weapon</param>
        protected BadGuy(Vector2 _location, Vector2 _scrollValue, Bonus _bonusDroppedOnDeath, MovePattern _pattern, String[] flags, SpriteEffects flip, Rectangle spriteSrc, Vector2 speed, Vector2 scale, Weapon weapon)
            : base(_location, spriteSrc, speed, scale, 0.0f, 30000f)
        {
            this.dropOnDeath = _bonusDroppedOnDeath;
            this.movePattern = _pattern;
            this.scrollValue = _scrollValue;
            this.Flags = flags;

            if (_pattern != null)
            {
                bounce = false;
            }
            else
            {
                bounce = true;
            }

            this.onScreen = false;
            this.rotation = 0.0f;

            this.Flip = flip;
            this.Weapon = weapon;

            if (this.Weapon != null)
            {
                this.Weapon.Flip = flip;
            }

            this.Hitbox = new SquareHitbox(this);
            this.Removable = true;
            this.InfiniteMovePattern = false;
            this.Difficulty = 0;
            this.ttl = 120000;
            this.FiringLocation = Vectors.ConvertPointToVector2(DstRect.Center);
        }
 public Animation(Vector2 characterVelocity, TimeSpan timePerFrame, SpriteEffects effect, string[] sprites)
 {
     this.Sprites = sprites;
     this.TimePerFrame = timePerFrame;
     this.Effect = effect;
     this.CharacterVelocity = characterVelocity;
 }
Example #26
0
 public void DrawArm(SpriteBatch spriteBatch, Vector2 Position, Vector2 Origin, SpriteEffects effect = SpriteEffects.None)
 {
     if (armAni.ContainsKey(State))
     {
         armAni[State].Draw(spriteBatch, Position, Origin, effect);
     }
 }
        public void DrawByCenter(SpriteBatch sb, Vector2 location, SpriteEffects effects, float layerDepth)
        {
            Rectangle source = atlas.getSourceRectangle(currentFrame);
            Rectangle destination = new Rectangle((int)(location.X - (source.Width / 2)), (int)(location.Y - (source.Height / 2)), source.Width, source.Height);

            sb.Draw(atlas.getTexture(), destination, source, Color.White, 0, Vector2.Zero, effects, layerDepth);
        }
 // draw with sprite effect
 public static void DrawAnimation(this SpriteBatch spriteBatch, Animation animation, Vector2 position, float angle, SpriteEffects effect)
 {
     Point tile = animation.GetTile(animation.CurrentFrame);
     Rectangle source = new Rectangle(tile.X * animation.TileWidth, tile.Y * animation.TileHeight, animation.TileWidth, animation.TileHeight);
     Rectangle dest = new Rectangle(Round(position.X), Round(position.Y), animation.TileWidth, animation.TileHeight);
     spriteBatch.Draw(animation.Texture, dest, source, Color.White, angle, new Vector2(animation.TileWidth / 2, animation.TileHeight / 2), effect, 0);
 }
Example #29
0
        public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            DrawCommand cmd = GetRenderer().GetAvailableCommand();
            cmd.CommandType = DrawCommand.DrawCommandType.Texture;
            cmd.Texture = texture;
            cmd.Position = position;
            cmd.Color = color;

            // Vic says - make sure this stays in, or else previously-drawn Sprites can make later-drawn Sprites have the wrong effect
            cmd.ShaderEffect = null;

            cmd.Rotation = rotation;
            cmd.Origin = origin;
            if (sourceRectangle != null)
            {
                cmd.SourceRectangle = sourceRectangle.Value;
            }
            else
            {
                cmd.SourceRectangle = DoubleRectangle.Empty;
            }
            cmd.Scale = scale;
            cmd.Effects = effects;
            cmd.LayerDepth = layerDepth;
            cmd.CalculateDestinationRectangle(texture);
        }
Example #30
0
 public override void SetSpriteEffects(int i, int j, ref SpriteEffects effects)
 {
     if (i % 2 == 1)
     {
         effects = SpriteEffects.FlipHorizontally;
     }
 }
 public ScreenEffectData(Rectangle destinationRectangle, Rectangle sourceRectangle, Vector2 origin, float rotation, SpriteEffects effect, Color color, bool isDone, object caller)
 {
     Destination = destinationRectangle;
     Source      = sourceRectangle;
     Origin      = origin;
     Rotation    = rotation;
     Effect      = effect;
     Color       = color;
     IsDone      = isDone;
     Caller      = caller;
 }
Example #32
0
        public void DrawString
        (
            SpriteFont spriteFont,
            string text,
            Vector2 position,
            Color color,
            float rotation,
            Vector2 origin,
            float scale,
            SpriteEffects effects,
            float depth
        )
        {
            if (spriteFont == null)
            {
                throw new ArgumentException("spriteFont");
            }

            Vector2 p = new Vector2(-origin.X, -origin.Y);

            float sin = (float)Math.Sin(rotation);
            float cos = (float)Math.Cos(rotation);

            foreach (char c in text)
            {
                if (c == '\n')
                {
                    p.Y += spriteFont.LineSpacing;
                    p.X  = -origin.X;
                    continue;
                }
                if (spriteFont.characterData.ContainsKey(c) == false)
                {
                    continue;
                }
                GlyphData g = spriteFont.characterData[c];

                SpriteBatchItem item = _batcher.CreateBatchItem();

                item.Depth     = depth;
                item.TextureID = (int)spriteFont._texture.ID;

                texCoordTL.X = spriteFont._texture.Image.GetTextureCoordX(g.Glyph.X);
                texCoordTL.Y = spriteFont._texture.Image.GetTextureCoordY(g.Glyph.Y);
                texCoordBR.X = spriteFont._texture.Image.GetTextureCoordX(g.Glyph.X + g.Glyph.Width);
                texCoordBR.Y = spriteFont._texture.Image.GetTextureCoordY(g.Glyph.Y + g.Glyph.Height);

                if (effects == SpriteEffects.FlipVertically)
                {
                    float temp = texCoordBR.Y;
                    texCoordBR.Y = texCoordTL.Y;
                    texCoordTL.Y = temp;
                }
                else if (effects == SpriteEffects.FlipHorizontally)
                {
                    float temp = texCoordBR.X;
                    texCoordBR.X = texCoordTL.X;
                    texCoordTL.X = temp;
                }

                item.Set
                (
                    position.X,
                    position.Y,
                    p.X * scale,
                    (p.Y + g.Cropping.Y) * scale,
                    g.Glyph.Width * scale,
                    g.Glyph.Height * scale,
                    sin,
                    cos,
                    color,
                    texCoordTL,
                    texCoordBR
                );

                p.X += (g.Kerning.Y + g.Kerning.Z + spriteFont.Spacing);
            }
        }
        public static void DrawString(this SpriteBatch spriteBatch, BitmapFont bitmapFont, StringBuilder text, Vector2 position,
                                      Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float layerDepth, Rectangle?clippingRectangle = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (effect != SpriteEffects.None)
            {
                throw new NotSupportedException($"{effect} is not currently supported for {nameof(BitmapFont)}");
            }

            var glyphs = bitmapFont.GetGlyphs(text, position);

            foreach (var glyph in glyphs)
            {
                if (glyph.FontRegion == null)
                {
                    continue;
                }
                var characterOrigin = position - glyph.Position + origin;
                spriteBatch.Draw(glyph.FontRegion.TextureRegion, position, color, rotation, characterOrigin, scale, effect, layerDepth, clippingRectangle);
            }
        }
 public static void DrawString(this SpriteBatch spriteBatch, BitmapFont font, StringBuilder text, Vector2 position,
                               Color color, float rotation, Vector2 origin, float scale, SpriteEffects effect, float layerDepth, Rectangle?clippingRectangle = null)
 {
     DrawString(spriteBatch, font, text, position, color, rotation, origin, new Vector2(scale, scale), effect, layerDepth, clippingRectangle);
 }
Example #35
0
        public void Draw(Texture2D texture, Rectangle?sourceRect, Rectangle destRect, Color4 color, Vector2 scale, float depth = 0, SpriteEffects effects = SpriteEffects.None)
        {
            // Flush if the current texture is valid
            // and the new texture differs from the current texture
            if (CurrentTexture.TextureId != -1 && texture.TextureId != CurrentTexture.TextureId)
            {
                Flush();
            }

            // Set the current texture to the new texture
            CurrentTexture = texture;

            // Flush if the vertex or index counts exceeds the maximum
            if (indexCount + 6 >= MAX_INDICES || vertexCount + 4 >= MAX_VERTICES)
            {
                Flush();
            }

            // Construct source rectangle
            Rectangle source = sourceRect ?? new Rectangle(0, 0, texture.Width, texture.Height);

            // Decompose destination rectangle
            float x = destRect.X;
            float y = destRect.Y;
            float w = destRect.Width * scale.X;
            float h = destRect.Height * scale.Y;

            // Decompose source rectangle
            float srcX = source.X;
            float srcY = source.Y;
            float srcW = source.Width;
            float srcH = source.Height;

            var topLeftCoord = new Vector2(
                x: srcX / (float)texture.Width,
                y: srcY / (float)texture.Height);

            var topRightCoord = new Vector2(
                x: (srcX + srcW) / (float)texture.Width,
                y: srcY / (float)texture.Height);

            var bottomLeftCoord = new Vector2(
                x: srcX / (float)texture.Width,
                y: (srcY + srcH) / (float)texture.Height);

            var bottomRightCoord = new Vector2(
                x: (srcX + srcW) / (float)texture.Width,
                y: (srcY + srcH) / (float)texture.Height);

            // Flip the texture horizontally if requested
            if (effects.HasFlag(SpriteEffects.FlipHorizontal))
            {
                SwapVec(ref topLeftCoord, ref topRightCoord);
                SwapVec(ref bottomLeftCoord, ref bottomRightCoord);
            }

            // Flip the texture horizontally if requested
            if (effects.HasFlag(SpriteEffects.FlipVertical))
            {
                SwapVec(ref topLeftCoord, ref bottomLeftCoord);
                SwapVec(ref topRightCoord, ref bottomRightCoord);
            }

            // Top left
            Vertices[vertexCount++] = new Vertex2D(
                new Vector3(x, y, depth),
                topLeftCoord,
                color
                );

            // Top right
            Vertices[vertexCount++] = new Vertex2D(
                new Vector3(x + w, y, depth),
                topRightCoord,
                color
                );

            // Bottom left
            Vertices[vertexCount++] = new Vertex2D(
                new Vector3(x, y + h, depth),
                bottomLeftCoord,
                color
                );

            // Bottom right
            Vertices[vertexCount++] = new Vertex2D(
                new Vector3(x + w, y + h, depth),
                bottomRightCoord,
                color
                );

            // Increment the index count
            indexCount += 6;
        }
        private void DrawAttachmentSprite(SpriteBatch spriteBatch, WearableSprite attachment, Sprite head, Vector2?sheetIndex, Vector2 drawPos, float scale, float depthStep, SpriteEffects spriteEffects = SpriteEffects.None)
        {
            if (attachment.InheritSourceRect)
            {
                if (attachment.SheetIndex.HasValue)
                {
                    attachment.Sprite.SourceRect = new Rectangle(CalculateOffset(head, attachment.SheetIndex.Value), head.SourceRect.Size);
                }
                else if (sheetIndex.HasValue)
                {
                    attachment.Sprite.SourceRect = new Rectangle(CalculateOffset(head, sheetIndex.Value.ToPoint()), head.SourceRect.Size);
                }
                else
                {
                    attachment.Sprite.SourceRect = head.SourceRect;
                }
            }
            Vector2 origin = attachment.Sprite.Origin;

            if (attachment.InheritOrigin)
            {
                origin = head.Origin;
                attachment.Sprite.Origin = origin;
            }
            else
            {
                origin = attachment.Sprite.Origin;
            }
            float depth = attachment.Sprite.Depth;

            if (attachment.InheritLimbDepth)
            {
                depth = head.Depth - depthStep;
            }
            attachment.Sprite.Draw(spriteBatch, drawPos, Color.White, origin, rotate: 0, scale: scale, depth: depth, spriteEffect: spriteEffects);
        }
Example #37
0
 public LawnItem(Texture2D texture, Vector2 position, SpriteEffects flipFlags)
 {
     Texture   = texture;
     Position  = position;
     FlipFlags = flipFlags;
 }
 /// <summary>   Submit a sprite for drawing in the current batch. </summary>
 ///
 /// <param name="spriteBatch">      The spriteBatch to act on. </param>
 /// <param name="atlas">            The atlas. </param>
 /// <param name="texture">          The texture. </param>
 /// <param name="position">         The position. </param>
 /// <param name="sourceRectangle">  Source rectangle. </param>
 /// <param name="color">            The color. </param>
 /// <param name="rotation">         The rotation. </param>
 /// <param name="origin">           The origin. </param>
 /// <param name="scale">            The scale. </param>
 /// <param name="effects">          The effects. </param>
 /// <param name="layerDepth">       Depth of the layer. </param>
 public static void Draw(this SpriteBatch spriteBatch, TextureAtlas atlas, string texture, Vector2 position, Rectangle?sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     atlas.Draw(spriteBatch, texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth);
 }
Example #39
0
 /// <summary>
 /// Submit a text string of sprites for drawing in the current batch.
 /// </summary>
 /// <param name="batcher">Batcher.</param>
 /// <param name="font">Font.</param>
 /// <param name="text">Text.</param>
 /// <param name="position">Position.</param>
 /// <param name="color">Color.</param>
 /// <param name="rotation">Rotation.</param>
 /// <param name="origin">Origin.</param>
 /// <param name="scale">Scale.</param>
 /// <param name="effects">Effects.</param>
 /// <param name="layerDepth">Layer depth.</param>
 public static void drawString(this Batcher batcher, IFont font, string text, Vector2 position, Color color, float rotation,
                               Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
 {
     batcher.drawString(font, text, position, color, rotation, origin, new Vector2(scale), effects, layerDepth);
 }
Example #40
0
        public void Draw(
            Texture2D texture,
            Rectangle destinationRectangle,
            Nullable <Rectangle> sourceRectangle,
            Color color,
            float rotation,
            Vector2 origin,
            SpriteEffects effect,
            float depth
            )
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            if (sourceRectangle.HasValue)
            {
                tempRect = sourceRectangle.Value;
            }
            else
            {
                tempRect.X      = 0;
                tempRect.Y      = 0;
                tempRect.Width  = texture.Width;
                tempRect.Height = texture.Height;
            }

            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL.X = tempRect.X * texWidthRatio;
                texCoordTL.Y = (tempRect.Y + tempRect.Height) * texHeightRatio;

                texCoordBR.X = (tempRect.X + tempRect.Width) * texWidthRatio;
                texCoordBR.Y = tempRect.Y * texHeightRatio;
            }
            else
            {
                texCoordTL.X = texture.Image.GetTextureCoordX(tempRect.X);
                texCoordTL.Y = texture.Image.GetTextureCoordY(tempRect.Y);
                texCoordBR.X = texture.Image.GetTextureCoordX(tempRect.X + tempRect.Width);
                texCoordBR.Y = texture.Image.GetTextureCoordY(tempRect.Y + tempRect.Height);
            }

            if ((effect & SpriteEffects.FlipVertically) != 0)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            if ((effect & SpriteEffects.FlipHorizontally) != 0)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set
            (
                destinationRectangle.X,
                destinationRectangle.Y,
                -origin.X,
                -origin.Y,
                destinationRectangle.Width,
                destinationRectangle.Height,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                texCoordTL,
                texCoordBR);
        }
Example #41
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 public override void Initialize()
 {
     base.Initialize();
     SpriteEffects = SpriteEffects.None;
 }
Example #42
0
        /// <summary>
        /// Advances the time position and draws the current frame for the animation.
        /// <\summary>
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, float rotation,
                         SpriteEffects spriteEffects, Color color = default(Color))
        {
            if (Animation == null)
            {
                throw new NotSupportedException("No animation is currently playing.");
            }

            if (object.Equals(color, default(Color)))
            {
                color = Color.White;
            }

            AnimationFinished = false;
            AnimationStarted  = false;

            // Process passing time.
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;

            while (time > Animation.FrameTime)
            {
                time -= Animation.FrameTime;

                // Advance the frame index; looping or clamping as appropriate
                if (Animation.IsLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;

                    if (frameIndex == 0)
                    {
                        AnimationFinished = true;
                    }


                    if (frameIndex == 1)
                    {
                        AnimationStarted = true;
                    }
                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);

                    if (frameIndex == 0)
                    {
                        AnimationFinished = true;
                    }

                    if (frameIndex == 1)
                    {
                        AnimationStarted = true;
                    }
                }
            }

            // Calculate the source rectangle of the current frame.
            Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0,
                                             Animation.FrameWidth, Animation.FrameHeight);

            // Draw the current frame.
            spriteBatch.Draw(Animation.Texture, position, source, color, rotation,
                             Origin, 1.0f, spriteEffects, 0.0f);
        }
Example #43
0
 public AnimatedSprite(List <Frame> frames, Vector2 Position, Texture2D Image, float Rotation, Vector2 Scale, SpriteEffects spriteEffects, Color Tint, TimeSpan frameRate) :
     base(Position, Image, Rotation, Scale, Tint, spriteEffects)
 {
     this.frames    = frames;
     currentFrame   = 0;
     this.frameRate = frameRate;
 }
Example #44
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            SpriteEffects rotation = direction.X == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

            currentSpriteSheet.Sprite.Draw(spriteBatch, position, Game1.Scale, rotation);
        }
Example #45
0
 public void Draw(SpriteBatch sb, Vector2 position, Color c, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     sb.Draw(images[Frame >= images.Length ? 0 : Frame], position, null, c, rotation, origin, scale, effects, layerDepth);
 }
Example #46
0
        public override bool PreDraw(SpriteBatch sb, Color drawColor)
        {
            Texture2D texBody       = mod.GetTexture("NPCs/Serris/Serris_Body"),
                      texFins       = mod.GetTexture("NPCs/Serris/Serris_Fins");
            Serris_Head serris_head = (Serris_Head)head.modNPC;

            Vector2 bodyOrig = new Vector2(32, 35),
                    finsOrig = new Vector2(52, 31);
            int bodyHeight   = texBody.Height / 10,
                finsHeight   = texFins.Height / 15;

            float bodyRot   = npc.rotation - 1.57f;
            float headRot   = head.rotation - 1.57f;
            Color bodyColor = npc.GetAlpha(Lighting.GetColor((int)npc.Center.X / 16, (int)npc.Center.Y / 16));

            SpriteEffects effects = SpriteEffects.None;

            if (head.spriteDirection == -1)
            {
                effects    = SpriteEffects.FlipVertically;
                bodyOrig.Y = bodyHeight - bodyOrig.Y;
                finsOrig.Y = finsHeight - finsOrig.Y;
            }
            int frame = serris_head.state - 1;

            if (serris_head.state == 4)
            {
                frame = serris_head.sbFrame + 3;
            }

            // If it's the last body part before the head, draw the fins.
            int yFrame = frame * (bodyHeight * 2);

            if ((int)npc.ai[1] == head.whoAmI)
            {
                for (int j = 0; j < 3; j++)
                {
                    int     finFrame  = finsHeight * j + frame * (finsHeight * 3);
                    Vector2 finPos    = new Vector2(4, -16);
                    float   bodyRot2  = bodyRot - (headRot - bodyRot);
                    Vector2 finRotPos = bodyRot.ToRotationVector2();
                    if (float.IsNaN(finRotPos.X) || float.IsNaN(finRotPos.Y))
                    {
                        finRotPos = -Vector2.UnitY;
                    }
                    if (j == 0)
                    {
                        finPos    = new Vector2(-14, -14);
                        finRotPos = Vector2.Normalize(Vector2.Lerp(finRotPos, bodyRot2.ToRotationVector2(), 0.5f));
                    }
                    if (j == 2)
                    {
                        finPos    = new Vector2(20, -16);
                        finRotPos = Vector2.Normalize(Vector2.Lerp(finRotPos, headRot.ToRotationVector2(), 0.5f));
                    }
                    if (head.spriteDirection == -1)
                    {
                        finPos.Y *= -1;
                    }
                    float finRot = finRotPos.ToRotation();
                    finRot += (((float)Math.PI / 16) - ((float)Math.PI / 8) * (1f - serris_head.mouthFrame)) * 0.5f * head.spriteDirection;
                    float   finPosRot   = finPos.ToRotation() + bodyRot;
                    Vector2 finalFinPos = npc.Center + finPosRot.ToRotationVector2() * finPos.Length();
                    sb.Draw(texFins, finalFinPos - Main.screenPosition, new Rectangle?(new Rectangle(0, finFrame, texFins.Width, finsHeight)),
                            bodyColor, finRot, finsOrig, 1f, effects, 0f);
                }
            }
            else
            {
                yFrame += bodyHeight;
            }

            sb.Draw(texBody, npc.Center - Main.screenPosition, new Rectangle?(new Rectangle(0, yFrame, texBody.Width, bodyHeight)),
                    bodyColor, bodyRot, bodyOrig, 1f, effects, 0f);

            return(false);
        }
Example #47
0
        public void DrawString(
            SpriteFont spriteFont,
            string text,
            Vector2 position,
            Color color,
            float rotation,
            Vector2 origin,
            Vector2 scale,
            SpriteEffects effects,
            float layerDepth
            )
        {
            /* FIXME: This method is a duplicate of DrawString(StringBuilder)!
             * The only difference is how we iterate through the string.
             * -flibit
             */
            CheckBegin("DrawString");
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (text.Length == 0)
            {
                return;
            }
            effects &= (SpriteEffects)0x03;

            /* We pull all these internal variables in at once so
             * anyone who wants to use this file to make their own
             * SpriteBatch can easily replace these with reflection.
             * -flibit
             */
            Texture2D        textureValue = spriteFont.textureValue;
            List <Rectangle> glyphData    = spriteFont.glyphData;
            List <Rectangle> croppingData = spriteFont.croppingData;
            List <Vector3>   kerning      = spriteFont.kerning;
            List <char>      characterMap = spriteFont.characterMap;

            // FIXME: This needs an accuracy check! -flibit

            // Calculate offsets/axes, using the string size for flipped text
            Vector2 baseOffset     = origin;
            float   axisDirX       = axisDirectionX[(int)effects];
            float   axisDirY       = axisDirectionY[(int)effects];
            float   axisDirMirrorX = 0.0f;
            float   axisDirMirrorY = 0.0f;

            if (effects != SpriteEffects.None)
            {
                Vector2 size = spriteFont.MeasureString(text);
                baseOffset.X  -= size.X * axisIsMirroredX[(int)effects];
                baseOffset.Y  -= size.Y * axisIsMirroredY[(int)effects];
                axisDirMirrorX = axisIsMirroredX[(int)effects];
                axisDirMirrorY = axisIsMirroredY[(int)effects];
            }

            Vector2 curOffset   = Vector2.Zero;
            bool    firstInLine = true;

            foreach (char c in text)
            {
                // Special characters
                if (c == '\r')
                {
                    continue;
                }
                if (c == '\n')
                {
                    curOffset.X  = 0.0f;
                    curOffset.Y += spriteFont.LineSpacing;
                    firstInLine  = true;
                    continue;
                }

                /* Get the List index from the character map, defaulting to the
                 * DefaultCharacter if it's set.
                 */
                int index = characterMap.IndexOf(c);
                if (index == -1)
                {
                    if (!spriteFont.DefaultCharacter.HasValue)
                    {
                        throw new ArgumentException(
                                  "Text contains characters that cannot be" +
                                  " resolved by this SpriteFont.",
                                  "text"
                                  );
                    }
                    index = characterMap.IndexOf(
                        spriteFont.DefaultCharacter.Value
                        );
                }

                /* For the first character in a line, always push the width
                 * rightward, even if the kerning pushes the character to the
                 * left.
                 */
                Vector3 cKern = kerning[index];
                if (firstInLine)
                {
                    curOffset.X += Math.Abs(cKern.X);
                    firstInLine  = false;
                }
                else
                {
                    curOffset.X += spriteFont.Spacing + cKern.X;
                }

                // Calculate the character origin
                Rectangle cCrop   = croppingData[index];
                Rectangle cGlyph  = glyphData[index];
                float     offsetX = baseOffset.X + (
                    curOffset.X + cCrop.X
                    ) * axisDirX;
                float offsetY = baseOffset.Y + (
                    curOffset.Y + cCrop.Y
                    ) * axisDirY;
                if (effects != SpriteEffects.None)
                {
                    offsetX += cGlyph.Width * axisDirMirrorX;
                    offsetY += cGlyph.Height * axisDirMirrorY;
                }

                // Draw!
                float sourceW = Math.Sign(cGlyph.Width) * Math.Max(
                    Math.Abs(cGlyph.Width),
                    MathHelper.MachineEpsilonFloat
                    ) / (float)textureValue.Width;
                float sourceH = Math.Sign(cGlyph.Height) * Math.Max(
                    Math.Abs(cGlyph.Height),
                    MathHelper.MachineEpsilonFloat
                    ) / (float)textureValue.Height;

                PushSprite(
                    textureValue,
                    cGlyph.X / (float)textureValue.Width,
                    cGlyph.Y / (float)textureValue.Height,
                    sourceW,
                    sourceH,
                    position.X,
                    position.Y,
                    cGlyph.Width * scale.X,
                    cGlyph.Height * scale.Y,
                    color,
                    offsetX / sourceW / (float)textureValue.Width,
                    offsetY / sourceH / (float)textureValue.Height,
                    (float)Math.Sin(rotation),
                    (float)Math.Cos(rotation),
                    layerDepth,
                    (byte)effects
                    );

                /* Add the character width and right-side
                 * bearing to the line width.
                 */
                curOffset.X += cKern.Y + cKern.Z;
            }
        }
 public void SetFlip(SpriteEffects flip)
 {
     this.flip = flip;
 }
Example #49
0
        // draw the currently active animation frame sprite
        public void draw(SpriteBatch spriteBatch, Vector2 scale, float rotation, Vector2 position, SpriteEffects effect)
        {
            if (m_sprites.Count() == 0)
            {
                return;
            }

            sprite.draw(spriteBatch, scale, rotation, position, effect);
        }
Example #50
0
 public DrawData(Texture2D texture, Vector2 position, Rectangle?sourceRect, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, int inactiveLayerDepth)
 {
     this.texture                 = texture;
     this.position                = position;
     this.sourceRect              = sourceRect;
     this.color                   = color;
     this.rotation                = rotation;
     this.origin                  = origin;
     this.scale                   = scale;
     this.effect                  = effect;
     this.destinationRectangle    = new Rectangle();
     this.shader                  = 0;
     this.ignorePlayerRotation    = false;
     this.useDestinationRectangle = false;
 }
Example #51
0
        public void Draw
        (
            Texture2D texture,
            Vector2 position,
            Nullable <Rectangle> sourceRectangle,
            Color color,
            float rotation,
            Vector2 origin,
            Vector2 scale,
            SpriteEffects effect,
            float depth
        )
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            Rectangle rect;

            if (sourceRectangle.HasValue)
            {
                rect = sourceRectangle.Value;
            }
            else
            {
                rect = new Rectangle(0, 0, texture.Image.ImageWidth, texture.Image.ImageHeight);
            }

            Vector2 texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
            Vector2 texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);

            if (effect == SpriteEffects.FlipVertically)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            else if (effect == SpriteEffects.FlipHorizontally)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set
            (
                position.X,
                position.Y,
                -origin.X * scale.X,
                -origin.Y * scale.Y,
                rect.Width * scale.X,
                rect.Height * scale.Y,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                texCoordTL,
                texCoordBR
            );
        }
Example #52
0
        public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects = SpriteEffects.None, float layerDepth = 0.0f)
        {
            Vector2 offset = new Vector2(0.0f, 0.0f);

            for (int i = 0; i < text.Length; i++)
            {
                char          c = text[i];
                FontCharacter fontChar;
                if (!spriteFont.characterMap.TryGetValue(c, out fontChar))
                {
                    if (!spriteFont.DefaultCharacter.HasValue || !spriteFont.characterMap.TryGetValue(spriteFont.DefaultCharacter.Value, out fontChar))
                    {
                        continue;
                    }
                }
                if (fontChar == null)
                {
                    continue;
                }

                Draw(spriteFont.texture, position + offset + new Vector2(fontChar.Offset.X, spriteFont.BaseLine + fontChar.Offset.Y), fontChar.TextureRegion, color, rotation, origin - offset, 1.0f, SpriteEffects.None, layerDepth);
                offset.X += fontChar.Advance;
                if (i < text.Length - 1)
                {
                    int kerning = 0;
                    if (spriteFont.kernings.TryGetValue(SpriteFont.getKerningKey(c, text[i + 1]), out kerning))
                    {
                        offset.X += kerning;
                    }
                }
            }
        }
Example #53
0
        /// <summary>
        /// Fonction membre à surcharger pour dessiner le sprite. Par défaut la this.texture est
        /// affichée à sa position.
        /// </summary>
        /// <param name="camera">Caméra indiquant la partie du monde présentement visible à l'écran (peut être nulle).</param>
        /// <param name="spriteBatch">Gestionnaire d'affichage en batch aux périphériques.</param>
        public virtual void Draw(float angle, Camera camera, SpriteBatch spriteBatch, SpriteEffects effects = SpriteEffects.None)
        {
            // On doit travailler avec une copie de PositionRect car on va mapper ses coordonnées
            // en celles du monde si on nous a fourni une caméra.
            Rectangle destRect = this.PositionRect;

            // Si une caméra est fournie, on s'assure que le sprite y est visible.
            if (camera == null || camera.EstVisible(destRect))
            {
                // Décaler la destination en fonction de la caméra avant de dessiner.
                if (camera != null)
                {
                    camera.Monde2Camera(ref destRect);
                }

                // Afficher le sprite.
                spriteBatch.Draw(this.Texture, destinationRectangle: destRect, rotation: angle, effects: effects);
            }
        }
Example #54
0
 public void Draw(Texture2D texture, Vector2 position, Nullable <Rectangle> sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth = 0.0f)
 {
     Draw(texture, position, sourceRectangle, color, rotation, origin, new Vector2(scale * texture.Width, scale * texture.Height), effects, layerDepth);//TODO?
 }
Example #55
0
 public void DrawString(SpriteFont spriteFont, System.Text.StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects = SpriteEffects.None, float layerDepth = 0.0f)
 {
     DrawString(spriteFont, text.ToString(), position, color, rotation, origin, scale, effects, layerDepth);
 }
Example #56
0
 public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects = SpriteEffects.None, float layerDepth = 0.0f)
 {
     DrawString(spriteFont, text, position, color, rotation, origin, new Vector2(scale, scale), effects, layerDepth);
 }
Example #57
0
        internal void DrawInternal(Texture2D texture,
                                   Vector4 destinationRectangle,
                                   Rectangle?sourceRectangle,
                                   Color color,
                                   float rotation,
                                   Vector2 origin,
                                   SpriteEffects effect,
                                   float depth,
                                   bool autoFlush)
        {
            var item = _batcher.CreateBatchItem();

            item.Depth   = depth;
            item.Texture = texture;

            if (sourceRectangle.HasValue)
            {
                _tempRect = sourceRectangle.Value;
            }
            else
            {
                _tempRect.X      = 0;
                _tempRect.Y      = 0;
                _tempRect.Width  = texture.Width;
                _tempRect.Height = texture.Height;
            }

            _texCoordTL.X = _tempRect.X / (float)texture.Width;
            _texCoordTL.Y = _tempRect.Y / (float)texture.Height;
            _texCoordBR.X = (_tempRect.X + _tempRect.Width) / (float)texture.Width;
            _texCoordBR.Y = (_tempRect.Y + _tempRect.Height) / (float)texture.Height;

            if ((effect & SpriteEffects.FlipVertically) != 0)
            {
                var temp = _texCoordBR.Y;
                _texCoordBR.Y = _texCoordTL.Y;
                _texCoordTL.Y = temp;
            }
            if ((effect & SpriteEffects.FlipHorizontally) != 0)
            {
                var temp = _texCoordBR.X;
                _texCoordBR.X = _texCoordTL.X;
                _texCoordTL.X = temp;
            }

            item.Set(destinationRectangle.X,
                     destinationRectangle.Y,
                     -origin.X,
                     -origin.Y,
                     destinationRectangle.Z,
                     destinationRectangle.W,
                     (float)Math.Sin(rotation),
                     (float)Math.Cos(rotation),
                     color,
                     _texCoordTL,
                     _texCoordBR);

            if (autoFlush)
            {
                FlushIfNeeded();
            }
        }
Example #58
0
 public void Draw(Texture2D texture, Vector2 position, RectangleF sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 size, SpriteEffects effects, float layerDepth)
 {
     batcher.Batches.Add(new SpriteBatcher.BatchItem(texture, position, sourceRectangle, color, rotation, origin, size, effects, layerDepth, sortMode));
 }
Example #59
0
 public Sprite(string imgkey, int x, int y, SpriteEffects orientation)
 {
     Initialize(imgkey, x, y, orientation);
 }
Example #60
0
        public void Draw
        (
            Texture2D texture,
            Vector2 position,
            Nullable <Rectangle> sourceRectangle,
            Color color,
            float rotation,
            Vector2 origin,
            float scale,
            SpriteEffects effect,
            float depth
        )
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            Rectangle rect;

            if (sourceRectangle.HasValue)
            {
                rect = sourceRectangle.Value;
            }
            else
            {
                rect = new Rectangle(0, 0, texture.Width, texture.Height);
            }

            Vector2 texCoordTL;            // = texture.Image.GetTextureCoord ( rect.X, rect.Y );
            Vector2 texCoordBR;            // = texture.Image.GetTextureCoord ( rect.X+rect.Width, rect.Y+rect.Height );


            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL = new Vector2(rect.X * texWidthRatio, (rect.Y + rect.Height) * texHeightRatio);
                texCoordBR = new Vector2((rect.X + rect.Width) * texWidthRatio,
                                         rect.Y * texHeightRatio);
            }
            else
            {
                texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
                texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);
            }

            if (effect == SpriteEffects.FlipVertically)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            else if (effect == SpriteEffects.FlipHorizontally)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set
            (
                position.X,
                position.Y,
                -origin.X * scale,
                -origin.Y * scale,
                rect.Width * scale,
                rect.Height * scale,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                texCoordTL,
                texCoordBR
            );
        }