Esempio n. 1
0
        /// <summary>
        /// Create a sprite using the database sprite information.  This does not do any checking to make sure
        /// the named sprite already exists.  Usually, what you want to do is to create your SpriteController and
        /// register your SpriteDatabase with the controller.  Then, when you ask the SpriteController for a sprite,
        /// if that sprite does not exist yet, it will create it from the database.
        /// </summary>
        /// <param name="ControllerToUse">The sprite controller that will end up controlling the sprite</param>
        /// <param name="TheDatabaseToUse">The database</param>
        /// <returns></returns>
        internal Sprite CreateSprite(SpriteController ControllerToUse, SpriteDatabase TheDatabaseToUse)
        {
            Sprite DestSprite = null;

            if (ControllerToUse == null)
            {
                return(null);
            }
            for (int index = 0; index < Animations.Count; index++)
            {
                AnimationInfo CurrentAnimation = Animations[index];
                Image         myImage          = TheDatabaseToUse.GetImageFromName(CurrentAnimation.ImageName, true);
                if (myImage == null)
                {
                    return(null);                  //break out if we do not have the image defined for this
                }
                AnimationType AT = CurrentAnimation.FieldsToUse;
                if (index == 0)
                {
                    AT = AnimationType.SpriteDefinition;              //the first one MUST be this.
                }
                switch (AT)
                {
                case AnimationType.SpriteDefinition:
                    if (DestSprite == null)   //Creating the sprite from scratch
                    {
                        DestSprite = new Sprite(CurrentAnimation.StartPoint, ControllerToUse, myImage, CurrentAnimation.Width, CurrentAnimation.Height, CurrentAnimation.AnimSpeed, CurrentAnimation.NumFrames);
                    }
                    else
                    {
                        DestSprite.AddAnimation(CurrentAnimation.StartPoint, myImage, CurrentAnimation.Width, CurrentAnimation.Height, CurrentAnimation.AnimSpeed, CurrentAnimation.NumFrames);
                    }
                    break;

                case AnimationType.Rotation:
                    DestSprite.AddAnimation(CurrentAnimation.AnimationToUse, CurrentAnimation.RotationDegrees);
                    break;

                case AnimationType.Mirror:
                    DestSprite.AddAnimation(CurrentAnimation.AnimationToUse, CurrentAnimation.MirrorHorizontally, CurrentAnimation.MirrorVertically);
                    break;
                }
            }
            int sizepercent = ViewPercent;

            if (sizepercent < 5)
            {
                sizepercent = 100;
            }
            if (sizepercent > 300)
            {
                sizepercent = 100;
            }
            double delta = (double)sizepercent / 100.0; //turn it into a double, and into something we can multiply.

            DestSprite.SetSize(new Size((int)(DestSprite.GetSize.Width * delta), (int)(DestSprite.GetSize.Height * delta)));
            DestSprite.SetName(SpriteName);
            //We have created a new sprite.  Now, return a duplicate of that sprite.
            return(DestSprite);
        }
Esempio n. 2
0
        /// <summary>
        /// If multiple frames are selected, retrieve all of their rectangles
        /// </summary>
        /// <returns></returns>
        private List <Rectangle> AnimationFrameAreas()
        {
            List <Rectangle> Frames = new List <Rectangle>();
            Point            start  = ChosenArea.Location;
            int animations;

            int.TryParse(tbNumFrames.Text, out animations);
            Frames.Add(ChosenArea);
            Image tImage = myDatabase.GetImageFromName(cbStartingImage.SelectedItem.ToString(), true);

            for (int i = 1; i < animations; i++)
            {
                start = new Point(start.X + ChosenArea.Width, start.Y);
                if (start.X >= tImage.Width)
                {
                    start.X  = 0;
                    start.Y += ChosenArea.Height;
                }
                Rectangle tRec = new Rectangle(start.X, start.Y, ChosenArea.Width, ChosenArea.Height);
                Frames.Add(tRec);
            }
            return(Frames);
        }