Beispiel #1
0
        public string Animate()
        {
            animationCount++;

            //this could be the first time this gets called, so make sure there's an animation loaded
            if (this.currentFrame == null)
            {
                this.currentFrameNum = 0;
                this.currentFrame = this.frames[0];
                return this.currentFrame.Id;
            }

            //if the animation frame is done being displayed, move on to the next frame in the animation
            if (currentFrameNum >= this.currentFrame.DisplayLength)
            {
                this.nextFrame();
            }
            else
            {
                //mark the frame as having been shown for another render cycle
                currentFrameNum++;
            }

            //return the id of the current frame being displayed
            return this.currentFrame.Id;
        }
Beispiel #2
0
        public Sprite(string spriteName, string fileName)
        {
            this.name = spriteName;
            AnimationFrame animFrame = new AnimationFrame(fileName, 0, 0);
            Animation anim = new Animation();
            anim.SetName("Idle");
            anim.AddFrame(animFrame);
            this.AddAnimation(anim);

            Sprite.loadedSprites.Add(this);
        }
        //create a new sprite intended for a single frame animation
        public static Sprite singleFrame(string name, int width, int height, string frameLocation, int xOffset, int yOffset)
        {
            AnimationFrame animfrm = new AnimationFrame(frameLocation, xOffset, yOffset);
            Animation annie = new Animation();
            annie.AddFrame(animfrm);

            Sprite newSprite = new Sprite(name);
            newSprite.Size = new Dimension(width, height);
            newSprite.AddAnimation(annie);

            return newSprite;
        }
        //create a new animation from a single sprite sheet with each x and y location being a new frame
        //public static Animation fromSpriteSheet(string imgSheetLocation, List<int, int> framePositions)
        //public static Animation fromSpriteSheet(string imgSheetLocation, int frameWidth, int frameHeight, int[,] framePositions)
        public static Animation FromSpriteSheet(string imgSheetLocation, int frameWidth, int frameHeight, List<Point> framePositions)
        {
            Animation resultAnim = new Animation();

            foreach (Point point in framePositions)
            {
                AnimationFrame animFrame = new AnimationFrame(
                    imgSheetLocation,
                    (int) Math.Round(point.x),
                    (int) Math.Round(point.y));
                resultAnim.AddFrame(animFrame);
            }

            return resultAnim;
        }
 public static Animation SingleFrame(AnimationFrame frame)
 {
     Animation returnAnim = new Animation();
     returnAnim.AddFrame(frame);
     return returnAnim;
 }
Beispiel #6
0
 public bool AddFrame(AnimationFrame sourceFrame)
 {
     this.frames.Add(sourceFrame);
     return true;
 }
Beispiel #7
0
        //change the animation to display the next frame
        private void nextFrame()
        {
            //whether or not we found a new frame yet
            bool foundFrame = false;

            //if there's another frame after this one, go to that
            for (int i = 0; i < frames.Count; i++)
            {
                //if this is the current frame and there's another after
                if (frames[i] == this.currentFrame && i < frames.Count - 1)
                {
                    this.currentFrame = this.frames[i + 1];
                    foundFrame = true;
                    break;
                }
            }

            //there's no frame after the current one, so start back at the first frame
            if (foundFrame == false)
            {
                this.currentFrame = this.frames[0];
            }

            //reset the number of times the frame has been displayed
            this.currentFrameNum = 0;
        }