Exemplo n.º 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;
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public Sprite(SpriteDefinition sprite)
        {
            m_definition = new Asset <SpriteDefinition>(sprite);
            m_animations = new Dictionary <string, SpriteAnimation>();

            m_definition.OnAssetChanged += new OnChange(spriteAsset_OnAssetChanged);

            Reset(m_definition.Content);
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
 public static Sprite Create(SpriteDefinition def)
 {
     return(new Sprite(def));
 }