githubEdit

SpriteEditorScene

Introduction

A SpriteEditorScene is a "ready to save" or "just loaded" Scenearrow-up-right. It is used to load a Scene from a .scnx file and it can be used to write .scnx files easily. The FlatRedBallServicesarrow-up-right 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 herearrow-up-right.

Loading a .scnx into a Scene

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 methodarrow-up-right.

The following code shows how to load a .scnx file using the SpriteEditorScene instead of the FlatRedBallServices method:

Add the following using statement:

using FlatRedBall.Content;

Add the following to initialize after initializing FlatRedBall:

string fileName = "SplashScreen\SplashScreen.scnx";
string contentManagerName = "ContentManagerName";
SpriteEditorScene saveObject = SpriteEditorScene.FromFile(fileName);
Scene scene = saveObject.ToScene(contentManagerName );

scene.AddToManagers();
SplashScreen.png

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 managerarrow-up-right name. For more information on content managers, see the FlatRedBall content managerarrow-up-right 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.

Loading a .scnx into a SpriteEditorScene

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 SpriteSavearrow-up-right class, see the SpriteSave pagearrow-up-right.

Saving a .scnx

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 Scenearrow-up-right 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.

Manually constructing a .scnx

If you would like more control over how your .scnx is created, you can manually construct SpriteEditorScenes to be saved. To do this:

Saving Sprites

The following code creates 20 Spritesarrow-up-right and saves them to a .scnx file.

Add the following using statement:

In Initialize:

First the SpriteEditorScene instance is created. Next 20 Spritesarrow-up-right are created. These Spritesarrow-up-right will both appear in the application when it runs as well as saved in the SpriteEditorScene. Next, each Spritearrow-up-right is represented by a SpriteSave which has its properties set then is added to the SpriteEditorScene.

Once all Spritesarrow-up-right 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.

Executing the code:SpritesInCode.png

.scnx loaded in the SpriteEditor:FromCodeToSpriteEditor.png

Saving SpriteGrids

The following code creates a SpriteGridarrow-up-right with a different Texture2D displayed by the center Spritearrow-up-right.

Add the following using statements:

In Initialize:

Executing the code:SpriteGridCreatedInCode.png

.scnx loaded in the SpriteEditor:SpriteGridFromCodeInSpriteEditor.png

SpriteEditorScene Members

Did this article leave any questions unanswered? Post any question in our forumsarrow-up-right for a rapid response.

Last updated

Was this helpful?