First steps, please help

I am very sorry, but looking at the samples, I understand absolutely nothing. And the documentation is not helpful if one wants to get started.

To learn the basics, I want to create a very simple game: A sprite character that I can move left and right.

So I created a new Game, added a SpriteGroup in the Assets folder and added one line of code according to this document. My code now looks like this:

using System.Threading.Tasks;
using SiliconStudio.Core.Mathematics;
using SiliconStudio.Paradox;
using SiliconStudio.Paradox.Effects;
using SiliconStudio.Paradox.Graphics;

namespace SpriteAndBackground
{
    public class SpriteAndBackgroundGame : Game
    {
        public SpriteAndBackgroundGame()
        {
            // Target 9.1 profile by default
            GraphicsDeviceManager.PreferredGraphicsProfile = new[] { GraphicsProfile.Level_9_1 };
        }

        protected override async Task LoadContent()
        {
            await base.LoadContent();

            CreatePipeline();

            // Add custom game init at load time here
            var megaman = Asset.Load<SpriteGroup>("megaman");

            // Add a custom script
            Script.Add(GameScript1);
        }

        private void CreatePipeline()
        {
            // Setup the default rendering pipeline
            RenderSystem.Pipeline.Renderers.Add(new CameraSetter(Services));
            RenderSystem.Pipeline.Renderers.Add(new RenderTargetSetter(Services) { ClearColor = Color.CornflowerBlue });
            RenderSystem.Pipeline.Renderers.Add(new ModelRenderer(Services, "SpriteAndBackgroundEffectMain"));
            RenderSystem.Pipeline.Renderers.Add(new UIRenderer(Services));
        }

        private async Task GameScript1()
        {
            while (IsRunning)
            {
                // Wait next rendering frame
                await Script.NextFrame();

                // Add custom code to run every frame here (move entity...etc.)
                // ...
            }
        }
    }
}

I was expecting to see the SpriteGroup, but I only see a blue background. So, how do I display the SpriteGroup?

Hi Borkason,

You can’t just load you SpriteGroup to display it on your screen.

At first you must add a renderer for your sprites. Add the following line in your function CreatePipeline.

RenderSystem.Pipeline.Renderers.Add(new SpriteRenderer(Services));

Then you must declare a few private attributes at the top of your Class SpriteAndBackgroundGame

Entity megaman;
SpriteGroup megamanSpriteGroup;
SpriteComponent megamanSpriteComponent;
TransformationComponent megamanSpriteComponent;

Entities are core of the Paradox Engine. It has automatics mecanisms which works with Entities and every objects in your game are entities.

The megamanSpriteGroup attribute will contain the SpriteGroup you have created in the Paradox editor.
The megamanSpriteComponent attribute will manage all about animations on your Entity.
The megamanSpriteComponent attribute will manage position and effects on your Entity.

Then you must load your assets in the function LoadContent()

this.megaman = Asset.load<Entity>("megaman");
this.megamanSpriteGroup = Asset.load<SpriteGroup("megamanSpriteGroup")>;

Then you must retrieve the SpriteComponent and the TranformationComponent of your Entity ( again in the function LoadContent() )

this.megamanSpriteComponent = this.megaman.get<SpriteComponent>();
this.megamanTransformationComponent = this.megaman.get<TransformationComponent>();

Then you must assign your SpriteGroup to your SpriteComponent

this.megamanSpriteComponent.SpriteGroup = this.megamanSpriteGroup;

Then you must assign a initial position for your Entity at the TransformationComponent

this.megamanTransformationComponent.Translation = new Vector3(50,50,0);

Then you must add your Entity to the Entities Collection of the Game. The Game now knows your Entity and will apply some functions to it at each loop of the Game.

this.Entities.Add(this.megaman);

Finally, in the function GameScript which is your game loop you must add before the while this line. It will start the animation of your Sprite and display it on the screen.

this.SpriteAnimation.Play(this.megamanSpriteComponent,0,this.megamanSpriteGroup.Images.Count - 1, AnimationRepeatMode.LoopInfinite,2);

The last parameter represent the number of images you want to show in one second.

Sorry for my bad english. I hope it to be helpful for you.

1 Like

I figured that I have to set up a camera, or I won’t see any sprites.

private static readonly Vector3 GameVirtualResolution = new Vector3(640, 480, 20f);
private Entity camera;
protected override async Task LoadContent()
{
    // ...
    camera = new Entity("Camera") { new CameraComponent { UseProjectionMatrix = true, ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(VirtualResolution) } };
    Entities.Add(camera);

    CreatePipeline();
    // ...
}

private void CreatePipeline()
{
    // Setup the default rendering pipeline
    RenderSystem.Pipeline.Renderers.Add(new CameraSetter(Services) { Camera = camera.Get<CameraComponent>() });
    RenderSystem.Pipeline.Renderers.Add(new RenderTargetSetter(Services) { ClearColor = Color.CornflowerBlue });
    RenderSystem.Pipeline.Renderers.Add(new SpriteRenderer(Services));
}

It seems weird, i didn’t have to set up any camera. Are you making a 3D game ?

No, I am only using sprites and a background. When I remove the camera I only see the background, but no sprites.

It’s weird since my paradox studio has been updated i can’t see my sprites anymore on all my projects… Can you post some code on how to set up a camera ?

( I tried the code on the other post but it changes nothing, Maybe there are some lines missing ? )

EDIT : So you were right about the camera. It seems that i was working on an old build of the framework and now it need a camera to show up sprites.

To set up a camera first you must declare a camera attribute in your Game class :

private Entity camera;

Then you must instanciate the camera before the function CreatePipeline is called

camera = new Entity("Camera") { new CameraComponent { UseProjectionMatrix = true, ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(VirtualResolution) } };
        Entities.Add(camera);

Finally you must add the camera Entity to the cameraRenderer in the function CreatePipeline

RenderSystem.Pipeline.Renderers.Add(new CameraSetter(Services) { Camera = camera.Get<CameraComponent>() });

I read your edit, but anyway, the order of the pipeline-lines does matter in my case.