The SpriteEditorScene's Camera property is a CameraSave which stores information about the FlatRedBall.Camera.
This property is by default not used when loading a .scnx file by the engine. It is primarily used to store the position of the Camera in tools like the SpriteEditor and TileEditor. However, this member can be accessed to set a Camera's properties to match what has been saved.
For information on how to use the SpriteEditorScene's Camera property, see the CameraSave page.
A SpriteEditorScene is a "ready to save" or "just loaded" Scene. It is used to load a Scene from a .scnx file and it can be used to write .scnx files easily. The FlatRedBallServices class internally uses the SpriteEditorScene class when you use it to load Scenes.
You will not need to use the SpriteEditorScene class in most cases because you can load .scnx files through the FlatRedBallServices.Load method as shown here.
Using the SpriteEditorScene can give you additional information and control over how Scenes are created. In most cases you will want to use the FlatRedBallServices' Load method.
The following code shows how to load a .scnx file using the SpriteEditorScene instead of the FlatRedBallServices method:
Add the following using statement:
Add the following to initialize after initializing FlatRedBall:
The SpriteEditorScene.FromFile method loads and returns an instance of a SpriteEditorScene which is loaded from the argument .scnx. This SpriteEditorScene is then converted to a Scene by calling the ToScene method. The ToScene method takes a content manager name. For more information on content managers, see the FlatRedBall content manager entry.
Next, the Scene adds all of its contained objects to the appropriate managers through the AddToManagers method. Prior to calling AddToManagers all objects referenced by the Scene are stored in memory but they are not managed or drawn.
The example above which loads a .scnx into a Scene has the following compound line:
This could be broken up into:
The SpriteEditorScene is an "intermediary" type that is used to create a Scene; however there are situations where you may want to use the intermediary SpriteEditorScene in your game.
For example, consider a situation where you want to position Entities inside the SpriteEditor. Unfortunately the spriteEditor only supports the creation of .scnx files; however, you can load the .scnx into a SpriteEditorScene then instantiate Entities according to the position of Sprites in your .scnx. The following example shows what this code would look like assuming you have an Entity called Coin;
For more information on the SpriteSave class, see the SpriteSave page.
FlatRedBall provides code to save .scnx files from FlatRedBall applications. This allows the saving of .scnx files for custom scene building and debugging. Any .scnx file created with FlatRedBall will be loadable in the SpriteEditor.
To save a Scene, you must first create a SpriteEditorScene instance. You can create a SpriteEditorScene either from a Scene instance, or by manually creating the objects.
The easiest way to save a .scnx file is to first create a Scene, then use the SpriteEditorScene's static FromScene method.
For example, the following code creates and saves a .scnx file.
If you would like more control over how your .scnx is created, you can manually construct SpriteEditorScenes to be saved. To do this:
Instantiate a SpriteEditorScene
Create "Save" objects which represent FlatRedBall objects (Sprites, SpriteGrids, SpriteFrames, Texts) and set their properties and fields appropriately.
Add the "Save" objects to the SpriteEditorScene.
Save the SpriteEditorScene (which serializes it to an XML file).
The following code creates 20 Sprites and saves them to a .scnx file.
Add the following using statement:
In Initialize:
First the SpriteEditorScene instance is created. Next 20 Sprites are created. These Sprites will both appear in the application when it runs as well as saved in the SpriteEditorScene. Next, each Sprite is represented by a SpriteSave which has its properties set then is added to the SpriteEditorScene.
Once all Sprites have been created the Scene is saved to a .scnx file. Be sure to use a .scnx extension so the SpriteEditor recognizes this file as a valid scene.
The following code creates a SpriteGrid with a different Texture2D displayed by the center Sprite.
Add the following using statements:
In Initialize:
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
Executing the code:
.scnx loaded in the SpriteEditor:
Executing the code:
.scnx loaded in the SpriteEditor: