Пример #1
0
 public override Rectangle popRect()
 {
     //if the current stream has reached its final frame, we need to get the next animation in the group or loop the group itself.
     if (currentStream.streamComplete)
     {
         //if there is still another animation left, go get it.
         if (currentStreamIndex < streams.Length - 1)
         {
             //by resetting the current stream, when we loop back to it (if this object does loop that is), it will play from frame 1.
             //if we do not reset it, it would already be fully animated next time we attempt to play it
             currentStream.resetStream();
             //incremenet currentStream index and get the next animation in the group.
             currentStream = streams[++currentStreamIndex];
         }
             //this check on does loop may not be needed if we fix the frame increment isdues listed below. For we, we have to handle looping if it exists.
         else if(doesLoop)
         {
             resetStream();
         }
     }
     //TODO: because of objects like DelayedSpriteStream, its possible base.popRect() here will increment the frame when in reality, it should stay as was,
     //until DelayedSpriteStream object truly animates a new frame of animation.
     base.popRect();
     //return the stream of the current animation of the group.
     return currentStream.popRect();
 }
Пример #2
0
 public override void resetStream()
 {
     currentStream.resetStream();
     currentStream = streams[0];
     currentStreamIndex = 0;
     base.resetStream();
 }
Пример #3
0
 public DelayedSpriteStream(SpriteStreamBase stream, int frameDelay)
     : base(0)
 {
     this.stream = stream;
     this.frameDelay=frameDelay;
     frameElapse = frameDelay;
 }
Пример #4
0
 //StreamGroup still needs a frame count for its animation.
 public static int getFrameCount(SpriteStreamBase[] streams)
 {
     int frameCount = 0;
     for (int i = 0; i < streams.Length; i++)
     {
         frameCount += streams[i].totalFrames;
     }
     return frameCount;
 }
Пример #5
0
        protected override void LoadContent()
        {
            base.LoadContent();

            Rectangle spriteRect = new Rectangle(0, 0, 36, 36);
            sprite = new LinearSprite(Game.Content.Load<Texture2D>("Images/Ball"), Game1.spriteBatch, spriteRect);
            Rectangle[] rects = new Rectangle[] { new Rectangle(0, 0, spriteRect.Width, spriteRect.Height) };
            idle = new DelayedSpriteStream(new ExplicitSpriteStream(rects, true), 1);

            sprite.updateStream(idle);
        }
Пример #6
0
        //updateStream swaps out the current animation fot the one defined in the parameter. Next time drawSprite is called, it will be the new sprite animation.
        public void updateStream(SpriteStreamBase newStream)
        {
            //reset old steam so it can be displayed correctly again later
            //upon first setting currentStream, the value would in fact be null;
            //we also allow the same stream to be set, but just dont reset it. FUTURE: reset sprite when set again, make developers be more strict on when they set a new stream
            if (currentStream != newStream && currentStream!=null)
            {
                currentStream.resetStream();
            }

            currentStream = newStream;
        }
Пример #7
0
 public StreamGroup(SpriteStreamBase[] streams)
     : this(streams, false)
 {
 }
Пример #8
0
 public StreamGroup(SpriteStreamBase[] streams, Boolean doesLoop)
     : base(StreamGroup.getFrameCount(streams),doesLoop)
 {
     currentStream = streams[0];
     this.streams = streams;
 }
Пример #9
0
        protected override void LoadContent()
        {
            base.LoadContent();

            Rectangle spriteRect = new Rectangle(0, 0, 36, 74);
            sprite = new LinearSprite(Game.Content.Load<Texture2D>("Images/WolfSprite"), Game1.spriteBatch, spriteRect);
            Rectangle[] rects = new Rectangle[] { new Rectangle(0, 0, spriteRect.Width, spriteRect.Height), new Rectangle(spriteRect.Width, 0, spriteRect.Width, spriteRect.Height), new Rectangle(spriteRect.Width*2, 0, spriteRect.Width, spriteRect.Height) };
            run = new DelayedSpriteStream(new ExplicitSpriteStream(rects, true), 2);

            rects = new Rectangle[] { new Rectangle(spriteRect.Width * 3, 0, spriteRect.Width, spriteRect.Height), new Rectangle(spriteRect.Width * 4, 0, spriteRect.Width, spriteRect.Height), new Rectangle(0, spriteRect.Height, spriteRect.Width, spriteRect.Height), new Rectangle(spriteRect.Width, 0, spriteRect.Width, spriteRect.Height) };
             jog = new DelayedSpriteStream(new ExplicitSpriteStream(rects,true),4);
             rects = new Rectangle[] { new Rectangle(spriteRect.Width * 2, spriteRect.Height, spriteRect.Width, spriteRect.Height),
             new Rectangle(spriteRect.Width * 3, 0, spriteRect.Width, spriteRect.Height),
             new Rectangle(spriteRect.Width * 4, spriteRect.Height, spriteRect.Width, spriteRect.Height),
             new Rectangle(0, spriteRect.Height*2, spriteRect.Width, spriteRect.Height) ,
             new Rectangle(spriteRect.Width, spriteRect.Height*2, spriteRect.Width, spriteRect.Height) ,
             new Rectangle(spriteRect.Width * 2, spriteRect.Height*2, spriteRect.Width, spriteRect.Height) ,
             new Rectangle(spriteRect.Width * 3, spriteRect.Height*2, spriteRect.Width, spriteRect.Height) ,
             new Rectangle(spriteRect.Width * 4, spriteRect.Height*2, spriteRect.Width, spriteRect.Height)
             };
             walk = new DelayedSpriteStream(new ExplicitSpriteStream(rects, true), 8);
             rects = new Rectangle[] {  new Rectangle(spriteRect.Width * 2, spriteRect.Height, spriteRect.Width, spriteRect.Height)
             };
             idle = new DelayedSpriteStream(new ExplicitSpriteStream(rects, true), 8);
            sprite.updateStream(idle);

            destRect = new Rectangle(0, 0, 36, 72);
        }