Example #1
0
        void Reset(SpriteDefinition spriteDefinition)
        {
            m_animations.Clear();
            if (spriteDefinition.Animations != null)
            {
                foreach (SpriteAnimationDefinition def in spriteDefinition.Animations)
                {
                    m_animations.Add(def.Name, new SpriteAnimation(def));
                }
            }
            else if (spriteDefinition.Texture != null)
            {
                SpriteAnimationDefinition def = new SpriteAnimationDefinition();
                def.Texture = spriteDefinition.Texture;
                m_animations.Add(spriteDefinition.DefaultAnimation, new SpriteAnimation(def));
            }
            SetAnimation(spriteDefinition.DefaultAnimation);
            SetAnimationIndex(m_currentAnimation.StartIndex);

            m_animationSpeed = spriteDefinition.AnimationSpeed;

            m_alpha       = spriteDefinition.Alpha;
            m_scale       = new Vector2(spriteDefinition.Scale, spriteDefinition.Scale);
            m_orientation = spriteDefinition.Orientation;
            m_color       = new Color(spriteDefinition.Color);
            m_mirror      = false;
        }
Example #2
0
        public static Sprite CreateFromTexture(String path)
        {
            var texAsset = Engine.AssetManager.GetAsset <Texture2D>(path);
            var animDef  = new SpriteAnimationDefinition();

            animDef.Texture = texAsset.Content;
            var spriteDef      = new SpriteDefinition();
            var SpriteDefAsset = new Asset <SpriteDefinition>(spriteDef);

            spriteDef.Animations = new SpriteAnimationDefinition[1] {
                animDef
            };
            texAsset.OnAssetChanged +=
                () =>
            {
                var newAnimDef = new SpriteAnimationDefinition();
                newAnimDef.Texture = texAsset.Content;
                SpriteDefAsset.Content.Animations = new SpriteAnimationDefinition[1] {
                    newAnimDef
                };
                SpriteDefAsset.Reload();
            };

            return(new Sprite(SpriteDefAsset));
        }
Example #3
0
        public SpriteAnimation(SpriteAnimationDefinition spriteAnimDefinition)
        {
            m_name = spriteAnimDefinition.Name;

            m_texture = spriteAnimDefinition.Texture;

            m_startIndex = spriteAnimDefinition.StartIndex;
            m_endIndex   = spriteAnimDefinition.EndIndex;

            m_frameCount = spriteAnimDefinition.FrameCount;

            m_frameTime = spriteAnimDefinition.FrameTime;
            m_loop      = spriteAnimDefinition.Loop;

            if (m_frameCount.X == 0)
            {
                m_frameCount.X = 1;
            }
            if (m_frameCount.Y == 0)
            {
                m_frameCount.Y = 1;
            }

            m_size.X = m_texture.Width / m_frameCount.X;
            m_size.Y = m_texture.Height / m_frameCount.Y;

            int nFrame = m_frameCount.X * m_frameCount.Y;

            if (m_endIndex == -1)
            {
                //If endIndex is unspecified, assume its the last frame in the animation
                m_endIndex = nFrame - 1;
            }
        }
Example #4
0
        public static Sprite CreateFromTexture(Texture2D texture)
        {
            var animDef = new SpriteAnimationDefinition();

            animDef.Texture = texture;

            var spriteDef = new SpriteDefinition();

            spriteDef.Animations = new SpriteAnimationDefinition[1] {
                animDef
            };
            return(new Sprite(spriteDef));
        }