Пример #1
0
 public Explosion(SpriteSheetAnimator animator, Vector2 position)
 {
     _animator = animator;
     _animator.Sprite.Position = position;
     _animator.IsLooping       = false;
     _animator.PlayAnimation("explode", Destroy);
 }
Пример #2
0
 public static void RecordAnimator(SpriteSheetAnimator animator)
 {
     foreach (SpriteSheetAnimationData animation in animator.animations)
     {
         RecordSpriteSheet(animation.sprites, animation.name);
     }
 }
 public static void Draw(this SpriteBatch spriteBatch, SpriteSheetAnimator animator)
 {
     if (animator == null) throw new ArgumentNullException(nameof(animator));
     
     if (animator.IsPlaying && animator.Sprite != null)
         Draw(spriteBatch, animator.Sprite);
 }
    public static Entity Instantiate(EntityArchetype archetype, SpriteSheetAnimator animator)
    {
        Entity e = EntityManager.CreateEntity(archetype);

        animator.currentAnimationIndex = animator.defaultAnimationIndex;
        SpriteSheetAnimationData startAnim = animator.animations[animator.defaultAnimationIndex];
        int      maxSprites = startAnim.sprites.Length;
        Material material   = SpriteSheetCache.GetMaterial(animator.animations[animator.defaultAnimationIndex].animationName);
        int      bufferID   = DynamicBufferManager.AddDynamicBuffers(DynamicBufferManager.GetEntityBuffer(material), material);

        var spriteSheetMaterial = new SpriteSheetMaterial {
            material = material
        };
        BufferHook bh = new BufferHook {
            bufferID = bufferID, bufferEnityID = DynamicBufferManager.GetEntityBufferID(spriteSheetMaterial)
        };

        EntityManager.SetComponentData(e, bh);
        EntityManager.SetComponentData(e, new SpriteSheetAnimation {
            maxSprites = maxSprites, play = startAnim.playOnStart, samples = startAnim.samples, repetition = startAnim.repetition
        });
        EntityManager.SetComponentData(e, new SpriteIndex {
            Value = startAnim.startIndex
        });
        EntityManager.SetSharedComponentData(e, spriteSheetMaterial);
        animator.managedEntity = e;
        SpriteSheetCache.entityAnimator.Add(e, animator);
        return(e);
    }
Пример #5
0
        public Zombie(SpriteSheetAnimationGroup animationGroup)
        {
            _animator = new SpriteSheetAnimator(animationGroup);
            _sprite = _animator.Sprite;

            State = ZombieState.Appearing;
            IsOnGround = false;
        }
Пример #6
0
        public Zombie(SpriteSheetAnimationGroup animationGroup)
        {
            _animator = new SpriteSheetAnimator(animationGroup);
            _sprite   = _animator.Sprite;

            State      = ZombieState.Appearing;
            IsOnGround = false;
        }
Пример #7
0
    public SpriteSheetAnimator Build(Point mousePos)
    {
        SpriteSheetAnimator ssa = new SpriteSheetAnimator();

        ssa.Load(SpriteSheetTexture, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(mousePos.X, mousePos.Y), 1f, Color.Black);

        return(ssa);
    }
Пример #8
0
 public Explosion(SpriteSheetAnimationGroup animations, Vector2 position, float radius)
 {
     _animator = new SpriteSheetAnimator(animations)
     {
         Sprite    = { Position = position, Scale = Vector2.One * radius * 0.2f },
         IsLooping = false
     };
     _animator.PlayAnimation("explode", Destroy);
 }
Пример #9
0
 public Explosion(SpriteSheetAnimationGroup animations, Vector2 position, float radius)
 {
     _animator = new SpriteSheetAnimator(animations)
     {
         Sprite = { Position = position, Scale = Vector2.One * radius * 0.2f },
         IsLooping = false
     };
     _animator.PlayAnimation("explode", Destroy);
 }
 public static void RecordAnimator(SpriteSheetAnimator animator)
 {
     foreach (SpriteSheetAnimationData animation in animator.animations)
     {
         KeyValuePair <Material, float4[]> atlasData = SpriteSheetCache.BakeSprites(animation.sprites, animation.animationName);
         SpriteSheetMaterial material = new SpriteSheetMaterial {
             material = atlasData.Key
         };
         DynamicBufferManager.GenerateBuffers(material);
         DynamicBufferManager.BakeUvBuffer(material, atlasData);
         renderInformation.Add(new RenderInformation(material.material, DynamicBufferManager.GetEntityBuffer(material.material)));
     }
 }
Пример #11
0
        public Zombie(TextureAtlas textureAtlas)
        {
            _sprite = new Sprite(textureAtlas[0])
            {
                OriginNormalized = new Vector2(0.5f, 1.0f)
            };

            _animator = new SpriteSheetAnimator(_sprite, textureAtlas);
            _animator.AddAnimation("appear", framesPerSecond: 8, firstFrameIndex: 0, lastFrameIndex: 10);
            _animator.AddAnimation("idle", framesPerSecond: 8, firstFrameIndex: 36, lastFrameIndex: 41);
            _animator.AddAnimation("walk", framesPerSecond: 8, firstFrameIndex: 19, lastFrameIndex: 28);
            _animator.AddAnimation("attack", framesPerSecond: 8, firstFrameIndex: 29, lastFrameIndex: 35);
            _animator.AddAnimation("die", framesPerSecond: 8, firstFrameIndex: 11, lastFrameIndex: 18);

            _animator.PlayAnimation("appear", ResumeIdle);
        }
Пример #12
0
        public Zombie(TextureAtlas textureAtlas)
        {
            _sprite = new Sprite(textureAtlas[0])
            {
                OriginNormalized = new Vector2(0.5f, 1.0f)
            };

            _animator = new SpriteSheetAnimator(_sprite, textureAtlas);
            _animator.AddAnimation("appear", framesPerSecond: 8, firstFrameIndex: 0, lastFrameIndex: 10);
            _animator.AddAnimation("idle", framesPerSecond: 8, firstFrameIndex: 36, lastFrameIndex: 41);
            _animator.AddAnimation("walk", framesPerSecond: 12, firstFrameIndex: 19, lastFrameIndex: 28);
            _animator.AddAnimation("attack", framesPerSecond: 8, firstFrameIndex: 29, lastFrameIndex: 35);
            _animator.AddAnimation("die", framesPerSecond: 8, firstFrameIndex: 11, lastFrameIndex: 18);

            State = ZombieState.Appearing;
            IsOnGround = false;
        }
    public static void Play(Entity e, string animationName = "")
    {
        SpriteSheetAnimator animator = SpriteSheetCache.GetAnimator(e);

        if (animationName == "")
        {
            animationName = animator.animations[animator.currentAnimationIndex].name;
        }
        int i = 0;

        foreach (SpriteSheetAnimationData animation in animator.animations)
        {
            if (animation.animationName == animationName)
            {
                SpriteSheetManager.SetAnimation(e, animation, animator.animations[animator.currentAnimationIndex].name);
                animator.currentAnimationIndex = i;
            }
            i++;
        }
    }
Пример #14
0
    public void RenderEveryTick(float dt)
    {
        ListPool <SpriteSheetAnimator.AnimInfo, BubbleManager> .PooledList pooledList = ListPool <SpriteSheetAnimator.AnimInfo, BubbleManager> .Allocate();

        SpriteSheetAnimator spriteSheetAnimator = SpriteSheetAnimManager.instance.GetSpriteSheetAnimator("liquid_splash1");

        foreach (Bubble bubble2 in bubbles)
        {
            Bubble bubble = bubble2;
            SpriteSheetAnimator.AnimInfo animInfo = default(SpriteSheetAnimator.AnimInfo);
            animInfo.frame       = spriteSheetAnimator.GetFrameFromElapsedTimeLooping(bubble.elapsedTime);
            animInfo.elapsedTime = bubble.elapsedTime;
            animInfo.pos         = new Vector3(bubble.position.x, bubble.position.y, 0f);
            animInfo.rotation    = Quaternion.identity;
            animInfo.size        = Vector2.one;
            animInfo.colour      = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
            SpriteSheetAnimator.AnimInfo item = animInfo;
            pooledList.Add(item);
        }
        pooledList.Recycle();
    }
    public static void Play(EntityCommandBuffer buffer, Entity e, BufferHook hook, string animationName = "")
    {
        SpriteSheetAnimator animator = SpriteSheetCache.GetAnimator(e);

        if (animationName == "")
        {
            animationName = animator.animations[animator.currentAnimationIndex].name;
        }
        int i = 0;

        foreach (SpriteSheetAnimationData animation in animator.animations)
        {
            if (animation.animationName == animationName)
            {
                SpriteSheetManager.SetAnimation(buffer, e, animation, hook);
                animator.currentAnimationIndex = i;
                return;
            }
            i++;
        }
    }
    //Build collision animation on either side of the contact surface scaled to the rec1 scale.
    public List <SpriteSheetAnimator> Build(Rectangle rec1, Rectangle rec2, Vector2 collisionOffset, Vector2 obj1Direction, float rec1Scale, Color color)
    {
        List <SpriteSheetAnimator> rtnAnims = new List <SpriteSheetAnimator>();

        SpriteSheetAnimator anim1 = new SpriteSheetAnimator();
        SpriteSheetAnimator anim2 = new SpriteSheetAnimator();

        //Reduce scale as we get above 1f since it starts to look strange
        if (rec1Scale > 1)
        {
            float overage = rec1Scale - 1f;
            overage = overage * .5f;

            rec1Scale = 1f + overage;
        }

        if (Math.Abs(collisionOffset.X) < Math.Abs(collisionOffset.Y)) //Left or Right side collision
        {
            if (obj1Direction.X > 0)                                   //Object 1 Right side collision
            {
                if (rec1.Top > rec2.Top)
                {
                    anim1.Load(SpriteSheetTextureWestTop, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec2.Left - (anim1.Bounds.Width / 2);
                    float y = rec1.Top - (anim1.Bounds.Height / 2);

                    anim1.Position = new Vector2(x, y);

                    rtnAnims.Add(anim1);
                }
                if (rec1.Bottom < rec2.Bottom)
                {
                    anim2.Load(SpriteSheetTextureWestBottom, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec2.Left - (anim2.Bounds.Width / 2);
                    float y = rec1.Bottom + (anim2.Bounds.Height / 2);

                    anim2.Position = new Vector2(x, y);

                    rtnAnims.Add(anim2);
                }
            }
            else //Object 1 Left side collision
            {
                if (rec1.Top > rec2.Top)
                {
                    anim1.Load(SpriteSheetTextureEastTop, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec2.Right + (anim1.Bounds.Width / 2);
                    float y = rec1.Top - (anim1.Bounds.Height / 2);

                    anim1.Position = new Vector2(x, y);

                    rtnAnims.Add(anim1);
                }
                if (rec1.Bottom < rec2.Bottom)
                {
                    anim2.Load(SpriteSheetTextureEastBottom, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec2.Right + (anim2.Bounds.Width / 2);
                    float y = rec1.Bottom + (anim2.Bounds.Height / 2);

                    anim2.Position = new Vector2(x, y);

                    rtnAnims.Add(anim2);
                }
            }
        }
        else //Top or Bottom side collision
        {
            if (obj1Direction.Y > 0) //Object 1 Bottom side collision
            {
                if (rec1.Left > rec2.Left)
                {
                    anim1.Load(SpriteSheetTextureNorthLeft, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec1.Left - (anim1.Bounds.Width / 2);
                    float y = rec2.Top - (anim1.Bounds.Height / 2);

                    anim1.Position = new Vector2(x, y);

                    rtnAnims.Add(anim1);
                }
                if (rec1.Right < rec2.Right)
                {
                    anim2.Load(SpriteSheetTextureNorthRight, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec1.Right + (anim2.Bounds.Width / 2);
                    float y = rec2.Top - (anim2.Bounds.Height / 2);

                    anim2.Position = new Vector2(x, y);

                    rtnAnims.Add(anim2);
                }
            }
            else //Object 1 Top side collision
            {
                if (rec1.Left > rec2.Left)
                {
                    anim1.Load(SpriteSheetTextureSouthLeft, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec1.Left - (anim1.Bounds.Width / 2);
                    float y = rec2.Bottom + (anim1.Bounds.Height / 2);

                    anim1.Position = new Vector2(x, y);

                    rtnAnims.Add(anim1);
                }
                if (rec1.Right < rec2.Right)
                {
                    anim2.Load(SpriteSheetTextureSouthRight, NumberOfFrames, 1, 0, FrameDurationMs, new Vector2(0, 0), rec1Scale, color);

                    float x = rec1.Right + (anim2.Bounds.Width / 2);
                    float y = rec2.Bottom + (anim2.Bounds.Height / 2);

                    anim2.Position = new Vector2(x, y);

                    rtnAnims.Add(anim2);
                }
            }
        }


        return(rtnAnims);
    }
Пример #17
0
 public void ChangeAnimation(string animationName)
 {
     SpriteSheetAnimator.Play(DynamicAnimationsDemo.character, animationName);
 }