Summary description for EditorSpriteInfo.
Inheritance: FlatRedBall.Sprite, ISpriteEditorObject
Exemplo n.º 1
0
        public static Sprite AddSprite(string spriteTexture, string nameToUse)
        {
            EditorSprite spriteCreated = new EditorSprite();

            #region Create the spriteCreated depending on the type in spriteTexture
            try
            {
                #region Is the texture null?

                if (string.IsNullOrEmpty(spriteTexture))
                {
                    spriteCreated.Texture        = null;
                    spriteCreated.Red            = GraphicalEnumerations.MaxColorComponentValue;
                    spriteCreated.ColorOperation = Microsoft.DirectX.Direct3D.TextureOperation.SelectArg2;
                }

                #endregion

                #region Create the Sprite with a .achx
                else if (spriteTexture.EndsWith(".ach") || spriteTexture.EndsWith(".achx") ||
                         spriteTexture.EndsWith(".gif"))
                {
                    if (spriteTexture.EndsWith(".gif"))
                    {
                        AnimationChain animationChain = AnimationChain.FromGif(spriteTexture, SceneContentManager);

                        spriteCreated.SetAnimationChain(animationChain);
                    }
                    else
                    {
                        AnimationChainListSave listSave = AnimationChainListSave.FromFile(spriteTexture);

                        spriteCreated.AnimationChains = listSave.ToAnimationChainList(SceneContentManager);
                    }
                    if (spriteCreated.AnimationChains.Count != 0)
                    {
                        spriteCreated.SetAnimationChain(spriteCreated.AnimationChains[0]);
                    }

                    spriteCreated.Animate = true;
                }
                #endregion

                #region Create the Sprite with an image
                else
                {
                    spriteCreated.Texture =
                        FlatRedBallServices.Load <Texture2D>(spriteTexture, SceneContentManager);
                }

                #endregion
            }
            catch (Microsoft.DirectX.Direct3D.InvalidDataException)
            {
                throw new Microsoft.DirectX.Direct3D.InvalidDataException();
            }
            #endregion

            SpriteManager.AddSprite(spriteCreated);



            KeepSpriteNameUnique <Sprite>(spriteCreated, nameToUse, mScene.Sprites);

            spriteCreated.X = Camera.X;
            spriteCreated.Y = Camera.Y;

            // If the camera's in ortho mode then we're likely making a 2D game, so set the PixelSize to .5
            if (SpriteManager.Camera.Orthogonal)
            {
                spriteCreated.PixelSize = .5f;
            }

            SetStoredAddToSE(spriteCreated, EditorProperties.PixelSize);

            return(spriteCreated);
        }
Exemplo n.º 2
0
        public void ConvertToSpriteFrameClick(Window callingWindow)
        {
            if (SpriteEditorSettings.EditingSprites && 
                GameData.EditorLogic.CurrentSprites.Count != 0)
            {
                SpriteFrame newSpriteFrame = new SpriteFrame(
                    GameData.EditorLogic.CurrentSprites[0].Texture, SpriteFrame.BorderSides.All);
                SpriteManager.AddSpriteFrame(newSpriteFrame);

                newSpriteFrame.X = GameData.EditorLogic.CurrentSprites[0].X;
                newSpriteFrame.Y = GameData.EditorLogic.CurrentSprites[0].Y;
                newSpriteFrame.Z = GameData.EditorLogic.CurrentSprites[0].Z;

                newSpriteFrame.ScaleX = GameData.EditorLogic.CurrentSprites[0].ScaleX;
                newSpriteFrame.ScaleY = GameData.EditorLogic.CurrentSprites[0].ScaleY;

                newSpriteFrame.RotationX = GameData.EditorLogic.CurrentSprites[0].RotationX;
                newSpriteFrame.RotationY = GameData.EditorLogic.CurrentSprites[0].RotationY;
                newSpriteFrame.RotationZ = GameData.EditorLogic.CurrentSprites[0].RotationZ;

                newSpriteFrame.Alpha = GameData.EditorLogic.CurrentSprites[0].Alpha;

                newSpriteFrame.Red = GameData.EditorLogic.CurrentSprites[0].Red;
                newSpriteFrame.Green = GameData.EditorLogic.CurrentSprites[0].Green;
                newSpriteFrame.Blue = GameData.EditorLogic.CurrentSprites[0].Blue;

                newSpriteFrame.Name = GameData.EditorLogic.CurrentSprites[0].Name;

                GameData.DeleteCurrentSprites();

                SpriteEditorSettings.EditingSpriteFrames = true;

                // add code for undoing this.

                GameData.Scene.SpriteFrames.Add(newSpriteFrame);
            }
            else if ( SpriteEditorSettings.EditingSpriteFrames && 
                GameData.EditorLogic.CurrentSpriteFrames.Count != 0)
            {
                /*
                 * Need to set the invisible parent Sprite's texture because it will be used
                 * to set the new EditorSprite's texture.  We could manually do this, but it's
                 * cleaner to just call SetFromRegularSprite and have that handle everything.
                 */
               
                GameData.EditorLogic.CurrentSpriteFrames[0].CenterSprite.Texture =
                    GameData.EditorLogic.CurrentSpriteFrames[0].Texture;

                EditorSprite es = new EditorSprite();

                es.SetFromRegularSprite(GameData.EditorLogic.CurrentSpriteFrames[0].CenterSprite);
                es.Name = GameData.EditorLogic.CurrentSpriteFrames[0].Name;
                es.ScaleX = GameData.EditorLogic.CurrentSpriteFrames[0].ScaleX;
                es.ScaleY = GameData.EditorLogic.CurrentSpriteFrames[0].ScaleY;

                GameData.DeleteSpriteFrame(GameData.EditorLogic.CurrentSpriteFrames[0], true);

                SpriteEditorSettings.EditingSprites = true;

                SpriteManager.AddSprite(es);
                GameData.SetStoredAddToSE(es, GameData.EditorProperties.PixelSize);

                //GameData.ihMan.AddInstruction(new seInstructions.CreateSprite(es));

                GuiData.ToolsWindow.paintButton.Unpress();

                GameData.Cursor.ClickSprite(es);
                 
            }
        }
        public void ConvertToSpriteFrameClick(Window callingWindow)
        {
            if (SpriteEditorSettings.EditingSprites &&
                GameData.EditorLogic.CurrentSprites.Count != 0)
            {
                SpriteFrame newSpriteFrame = new SpriteFrame(
                    GameData.EditorLogic.CurrentSprites[0].Texture, SpriteFrame.BorderSides.All);
                SpriteManager.AddSpriteFrame(newSpriteFrame);

                newSpriteFrame.X = GameData.EditorLogic.CurrentSprites[0].X;
                newSpriteFrame.Y = GameData.EditorLogic.CurrentSprites[0].Y;
                newSpriteFrame.Z = GameData.EditorLogic.CurrentSprites[0].Z;

                newSpriteFrame.ScaleX = GameData.EditorLogic.CurrentSprites[0].ScaleX;
                newSpriteFrame.ScaleY = GameData.EditorLogic.CurrentSprites[0].ScaleY;

                newSpriteFrame.RotationX = GameData.EditorLogic.CurrentSprites[0].RotationX;
                newSpriteFrame.RotationY = GameData.EditorLogic.CurrentSprites[0].RotationY;
                newSpriteFrame.RotationZ = GameData.EditorLogic.CurrentSprites[0].RotationZ;

                newSpriteFrame.Alpha = GameData.EditorLogic.CurrentSprites[0].Alpha;

                newSpriteFrame.Red   = GameData.EditorLogic.CurrentSprites[0].Red;
                newSpriteFrame.Green = GameData.EditorLogic.CurrentSprites[0].Green;
                newSpriteFrame.Blue  = GameData.EditorLogic.CurrentSprites[0].Blue;

                newSpriteFrame.Name = GameData.EditorLogic.CurrentSprites[0].Name;

                GameData.DeleteCurrentSprites();

                SpriteEditorSettings.EditingSpriteFrames = true;

                // add code for undoing this.

                GameData.Scene.SpriteFrames.Add(newSpriteFrame);
            }
            else if (SpriteEditorSettings.EditingSpriteFrames &&
                     GameData.EditorLogic.CurrentSpriteFrames.Count != 0)
            {
                /*
                 * Need to set the invisible parent Sprite's texture because it will be used
                 * to set the new EditorSprite's texture.  We could manually do this, but it's
                 * cleaner to just call SetFromRegularSprite and have that handle everything.
                 */

                GameData.EditorLogic.CurrentSpriteFrames[0].CenterSprite.Texture =
                    GameData.EditorLogic.CurrentSpriteFrames[0].Texture;

                EditorSprite es = new EditorSprite();

                es.SetFromRegularSprite(GameData.EditorLogic.CurrentSpriteFrames[0].CenterSprite);
                es.Name   = GameData.EditorLogic.CurrentSpriteFrames[0].Name;
                es.ScaleX = GameData.EditorLogic.CurrentSpriteFrames[0].ScaleX;
                es.ScaleY = GameData.EditorLogic.CurrentSpriteFrames[0].ScaleY;

                GameData.DeleteSpriteFrame(GameData.EditorLogic.CurrentSpriteFrames[0], true);

                SpriteEditorSettings.EditingSprites = true;

                SpriteManager.AddSprite(es);
                GameData.SetStoredAddToSE(es, GameData.EditorProperties.PixelSize);

                //GameData.ihMan.AddInstruction(new seInstructions.CreateSprite(es));

                GuiData.ToolsWindow.paintButton.Unpress();

                GameData.Cursor.ClickSprite(es);
            }
        }