Need a simpler tutorial for beginners

I know the basics of c# and everything, I want to use this engine and the high level tutorials on the documentation are really not helpful. I want a tutorial that details every step the engine is making, what starts the game, what controls what is happening at any given time. Am I missing something?

Did you read the code of samples projects ? The JumpyJet Sample is really useful to start creating a simple 2D game :wink:

No, it isn’t, really. If you are familiar with game programming, then maybe. JumpyJet is packed with stuff and there is too much going on at the same time.

This is way better (credits to Yvonnick_FRIN for helping me out in the other thread!). There may be some little errors, because I quickly cleaned the code from other stuff, but that basically shows you how to add a sprite and a background that can be moved to the left and to the right, aswell as setting the resolution. Yvonnick told me, a camera is not necessary, but I could not get it to work. without it.

You need to create the assets: a SpriteGroup “crane”, an Entity “crane_entity” containing the sprite “crane” and a Texture “background”.

using System.Threading.Tasks;
using SiliconStudio.Core.Mathematics;
using SiliconStudio.Paradox;
using SiliconStudio.Paradox.Effects;
using SiliconStudio.Paradox.Graphics;
using SiliconStudio.Paradox.EntityModel;
using SiliconStudio.Paradox.Engine;
using SiliconStudio.Paradox.Input;
using SiliconStudio.Paradox.DataModel;

namespace MyFirstGame
{
    public class MyFirstGameGame : Game
    {
        // Setting Virtual Resolution so that the screen has 640 and 1136 of Width and Height respectively.
        // Note that the Z component indicates the near and farplane [near, far] = [-10, 10].
        private static readonly Vector3 GameVirtualResolution = new Vector3(640, 480, 20f);
        private Entity camera;

        GameBoard gameBoard;
        Crane crane;

       
        public MyFirstGameGame()
        {
            // Target 9.1 profile by default
            GraphicsDeviceManager.PreferredGraphicsProfile = new[] { GraphicsProfile.Level_9_1 };

            // Set landscape preferred size for back buffer
            GraphicsDeviceManager.PreferredBackBufferWidth = (int)GameVirtualResolution.X;
            GraphicsDeviceManager.PreferredBackBufferHeight = (int)GameVirtualResolution.Y;
        }

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

            // Set virtual resolution for Sprite
            VirtualResolution = GameVirtualResolution;

            // Creates and add the game camera
            camera = new Entity("Camera") { new CameraComponent { UseProjectionMatrix = true, ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(VirtualResolution) } };
            Entities.Add(camera);

            CreatePipeline();

            // Add crane entity
            var crane_entity = new Crane(Asset.Load<Entity>("crane_entity"));
            Entities.Add(crane_entity);
            
            // set crane position
            crane_entity.Transformation.Translation.X = VirtualResolution.X / 2;
            crane_entity.Transformation.Translation.Y = VirtualResolution.Y / 2;


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

        private void CreatePipeline()
        {
            // Setup the default rendering pipeline
            // Create the camera setter. This sets the camera to use at each frame
            RenderSystem.Pipeline.Renderers.Add(new CameraSetter(Services) { Camera = camera.Get<CameraComponent>() });
            // Create the RenderTarget setter. This clears and sets the render targets

            RenderSystem.Pipeline.Renderers.Add(new RenderTargetSetter(Services));
            RenderSystem.Pipeline.Renderers.Add(new BackgroundRenderer(Services, "background"));
            RenderSystem.Pipeline.Renderers.Add(new SpriteRenderer(Services));
        }

        // InputState represents all command inputs from a user
        private enum InputState
        {
            None,
            LeftPressed,
            RightPressed
        }

        /// <summary>
        /// Determine input from a user from a keyboard.
        /// Left and Right arrow for running to left and right direction, Space for shooting.
        /// </summary>
        /// <returns></returns>
        private InputState GetKeyboardInputState()
        {
            if (Input.IsKeyPressed(Keys.Right))
            {
                return InputState.RightPressed;
            }
            else if (Input.IsKeyPressed(Keys.Left))
            {
                return InputState.LeftPressed;
            }
            else
            {
                return InputState.None;
            }
        }

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

                var inputState = GetKeyboardInputState();

                if (inputState == InputState.RightPressed)
                {
                    // Update Agent's position
                    crane_entity.Transformation.Translation.Y += 20;
                }
                else if (inputState == InputState.LeftPressed)
                {
                    // Update Agent's position
                    crane_entity.Transformation.Translation.Y += -20;
                }
            }
        }

        private async Task GameScript1()
        {
            //SpriteAnimation.Play(this.Entity.Get<SpriteComponent>(), 1, 19, AnimationRepeatMode.LoopInfinite, 12f);

            while (IsRunning)
            {
                // Wait next rendering frame
                await Script.NextFrame();

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

This actually looks helpful since it has comments in there. Thanks, hoping this helps!

1 Like