Пример #1
0
        public override void Start()
        {
            var virtualResolution = new Vector3(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height, 20f);

            // Create Parallax Background
            pal0SpriteSheet = Asset.Load<SpriteSheet>("pal0_sprite");
            pal1SpriteSheet = Asset.Load<SpriteSheet>("pal1_sprite");
            pal2SpriteSheet = Asset.Load<SpriteSheet>("pal2_sprite");
            backgroundParallax.Add(new BackgroundSection(pal0SpriteSheet.Sprites[0], virtualResolution, GameScript.GameSpeed / 4f, Pal0Depth));
            backgroundParallax.Add(new BackgroundSection(pal1SpriteSheet.Sprites[0], virtualResolution, GameScript.GameSpeed / 3f, Pal1Depth));
            backgroundParallax.Add(new BackgroundSection(pal2SpriteSheet.Sprites[0], virtualResolution, GameScript.GameSpeed / 1.5f, Pal2Depth));

            // For pal3Sprite: Ground, move it downward so that its bottom edge is at the bottom screen.
            var screenHeight = virtualResolution.Y;
            pal3SpriteSheet = Asset.Load<SpriteSheet>("pal3_sprite");
            var pal3Height = pal3SpriteSheet.Sprites[0].Region.Height;
            backgroundParallax.Add(new BackgroundSection(pal3SpriteSheet.Sprites[0], virtualResolution, GameScript.GameSpeed, Pal3Depth, Vector2.UnitY * (screenHeight - pal3Height) / 2));

            // allocate the sprite batch in charge of drawing the backgrounds.
            spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = virtualResolution };

            // register the renderer in the pipeline
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor);
            compositor.Master.Renderers.Insert(1, delegateRenderer = new SceneDelegateRenderer(DrawParallax));
        }
Пример #2
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            backgroundEffect = new Effect(Context.GraphicsDevice, BackgroundEffect.Bytecode) { Name = "BackgroundEffect" };
            spriteBatch = new SpriteBatch(Context.GraphicsDevice) { VirtualResolution = new Vector3(1)};
        }
Пример #3
0
        /// <summary>
        /// Draw a sprite using a sprite batch.
        /// </summary>
        /// <param name="sprite">The sprite</param>
        /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param>
        /// <param name="position">The position to which draw the sprite</param>
        /// <param name="color">The color to use to draw the sprite</param>
        /// <param name="rotation">The rotation to apply on the sprite</param>
        /// <param name="scales">The scale factors to apply on the sprite</param>
        /// <param name="depthLayer">The depth layer to which draw the sprite</param>
        /// <param name="spriteEffects">The sprite effect to apply on the sprite</param>
        /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(SiliconStudio.Paradox.Graphics.SpriteSortMode,SiliconStudio.Paradox.Graphics.Effect)"/> 
        /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks>
        /// <exception cref="ArgumentException">The provided frame index is not valid.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception>
        public static void Draw(this Sprite sprite, SpriteBatch spriteBatch, Vector2 position, Color color, Vector2 scales, float rotation = 0f, float depthLayer = 0, SpriteEffects spriteEffects = SpriteEffects.None)
        {
            if (spriteBatch == null) throw new ArgumentNullException("spriteBatch");

            if (sprite.Texture == null)
                return;

            spriteBatch.Draw(sprite.Texture, position, sprite.Region, color, rotation, sprite.Center, scales, spriteEffects, sprite.Orientation, depthLayer);
        }
Пример #4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Asset.Load<SpriteFont>("Font");

            wireframeState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back) { FillMode = FillMode.Wireframe });

            materials.Add(Asset.Load<Material>("NoTessellation"));
            materials.Add(Asset.Load<Material>("FlatTessellation"));
            materials.Add(Asset.Load<Material>("PNTessellation"));
            materials.Add(Asset.Load<Material>("PNTessellationAE"));
            materials.Add(Asset.Load<Material>("FlatTessellationDispl"));
            materials.Add(Asset.Load<Material>("FlatTessellationDisplAE"));
            materials.Add(Asset.Load<Material>("PNTessellationDisplAE"));

            var cube = new Entity("Cube") { new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel { Size = new Vector3(80), MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) };
            var sphere = new Entity("Sphere") { new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel { Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] }} ).GenerateModel(Services)) };

            var megalodon = new Entity { new ModelComponent { Model = Asset.Load<Model>("megalodon Model") } };
            megalodon.Transform.Position= new Vector3(0, -30f, -10f);

            var knight = new Entity { new ModelComponent { Model = Asset.Load<Model>("knight Model") } };
            knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0);
            knight.Transform.Position = new Vector3(0, -50f, 20f);
            knight.Transform.Scale= new Vector3(0.6f);

            entities.Add(sphere);
            entities.Add(cube);
            entities.Add(megalodon);
            entities.Add(knight);

            camera = new TestCamera();
            CameraComponent = camera.Camera;
            Script.Add(camera);

            LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true);
            GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White);

            ChangeModel(0);
            SetWireframe(true);

            camera.Position = new Vector3(25, 45, 80);
            camera.SetTarget(currentEntity, true);
        }
Пример #5
0
        public override void Start()
        {
            // create the ball sprite.
            var virtualResolution = new Vector3(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height, 1);
            spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = virtualResolution };
            sphere = Asset.Load<Texture>("sphere");

            // Initialize ball's state related variables.
            resolution = new Vector2(virtualResolution.X, virtualResolution.Y);
            ballHalfSize = new Vector2(SphereWidth / 2, SphereHeight / 2);
            ballPosition = resolution / 2;
            ballSpeed = new Vector2(600, -400);

            // Add Graphics Layer
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor);
            compositor.Master.Renderers.Add(delegateRenderer = new SceneDelegateRenderer(RenderSpheres));
        }
Пример #6
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            font = Asset.Load<SpriteFont>("Font");
            teapot = Asset.Load<Model>("Teapot");
            batch = new SpriteBatch(GraphicsDevice);

            BuildUI();

            spriteComponent = new SpriteComponent { SpriteProvider = new SpriteFromSheet { Sheet = Asset.Load<SpriteSheet>("SpriteSheet") } };
            modelComponent = new ModelComponent { Model = teapot };
            modelComponent2 = new ModelComponent { Model = teapot };
            modelComponent3 = new ModelComponent { Model = teapot };
            entity = new Entity { spriteComponent, modelComponent };
            entity2 = new Entity { modelComponent2 };
            entity3 = new Entity { modelComponent3 };
            SceneSystem.SceneInstance.Scene.Entities.Add(entity);
            SceneSystem.SceneInstance.Scene.Entities.Add(entity2);
            SceneSystem.SceneInstance.Scene.Entities.Add(entity3);

            if (Input.Accelerometer.IsSupported)
                Input.Accelerometer.IsEnabled = true;

            if (Input.Compass.IsSupported)
                Input.Compass.IsEnabled = true;

            if (Input.Gyroscope.IsSupported)
                Input.Gyroscope.IsEnabled = true;

            if (Input.UserAcceleration.IsSupported)
                Input.UserAcceleration.IsEnabled = true;

            if (Input.Gravity.IsSupported)
                Input.Gravity.IsEnabled = true;

            if (Input.Orientation.IsSupported)
                Input.Orientation.IsEnabled = true;

            ChangeScene(0);
        }
Пример #7
0
 /// <summary>
 /// Draw a sprite using a sprite batch and with white color and scale of 1.
 /// </summary>
 /// <param name="sprite">The sprite</param>
 /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param>
 /// <param name="position">The position to which draw the sprite</param>
 /// <param name="rotation">The rotation to apply on the sprite</param>
 /// <param name="depthLayer">The depth layer to which draw the sprite</param>
 /// <param name="spriteEffects">The sprite effect to apply on the sprite</param>
 /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(SiliconStudio.Paradox.Graphics.SpriteSortMode,SiliconStudio.Paradox.Graphics.Effect)"/> 
 /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks>
 /// <exception cref="ArgumentException">The provided frame index is not valid.</exception>
 /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception>
 public static void Draw(this Sprite sprite, SpriteBatch spriteBatch, Vector2 position, float rotation = 0, float depthLayer = 0, SpriteEffects spriteEffects = SpriteEffects.None)
 {
     sprite.Draw(spriteBatch, position, Color.White, Vector2.One, rotation, depthLayer, spriteEffects);
 }
Пример #8
0
        public override void Start()
        {
            base.Start();

            var installs = InstallationLocator.Locate();

            _spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = new Vector3(_virtualResolution, 1) };

            _artworkFactory = new ArtworkFactory(installs.First(), _container);
            _texmapFactory = new TexmapFactory(installs.First(), _container);
            _animationFactory = new AnimationFactory(installs.First(), _container);
            _gumpFactory = new GumpFactory(installs.First(), _container);
            _asciiFontFactory = new ASCIIFontFactory(installs.First(), _container);
            _unicodeFontFactory = new UnicodeFontFactory(installs.First(), _container);

            // register the renderer in the pipeline
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor);

            compositor.Master.Renderers.Add(new ClearRenderFrameRenderer());
            compositor.Master.Renderers.Add(new SceneDelegateRenderer(RenderQuad));
        }
Пример #9
0
        protected override Task LoadContent()
        {
            // Load the fonts
            spriteFont11 = Asset.Load<SpriteFont>("Arial");

            // load the round texture 
            roundTexture = Asset.Load<Texture>("round");

            // create the SpriteBatch used to render them
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // initialize parameters
            textHeight = spriteFont11.MeasureString(KeyboardSessionString).Y;
            screenSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height);
            roundTextureSize = new Vector2(roundTexture.Width, roundTexture.Height);

            // activate the gesture recognitions
            Input.ActivatedGestures.Add(new GestureConfigDrag());
            Input.ActivatedGestures.Add(new GestureConfigFlick());
            Input.ActivatedGestures.Add(new GestureConfigLongPress());
            Input.ActivatedGestures.Add(new GestureConfigComposite());
            Input.ActivatedGestures.Add(new GestureConfigTap());

            // add a task to the task scheduler that will be executed asynchronously 
            Script.AddTask(UpdateInputStates);

            return Task.FromResult(0);
        }
Пример #10
0
        public void DrawSprite(SpriteBatch spriteBatch)
        {
            // DrawParallax the first quad
            spriteBatch.Draw(texture, firstQuadPos + screenCenter, firstQuadRegion, Color.White, 0f, firstQuadOrigin, 1f, SpriteEffects.None, ImageOrientation.AsIs, depth);

            if (secondQuadRegion.Width > 0)
            {
                // DrawParallax the second quad
                spriteBatch.Draw(texture, secondQuadPos + screenCenter, secondQuadRegion, Color.White, 0f, secondQuadOrigin, 1f, SpriteEffects.None, ImageOrientation.AsIs, depth);
            }
        }
Пример #11
0
        public override void Start()
        {
            base.Start();

            var dataDirectory = Settings.UltimaOnline.DataDirectory;

            if (string.IsNullOrEmpty(dataDirectory) || !Directory.Exists(dataDirectory))
            {
                using (var form = new SelectInstallForm("CoreAdapterTests"))
                {
                    if (form.ShowDialog() == DialogResult.Cancel)
                    {
                        //TODO: End game
                    }

                    var version = form.SelectedInstall.Version;

                    Settings.UltimaOnline.DataDirectory = dataDirectory = form.SelectedInstall.Directory;
                    Settings.UltimaOnline.ClientVersion = version.ToString();
                }
            }

            var install = new InstallLocation(dataDirectory);

            _spriteBatch = new SpriteBatch(GraphicsDevice) {VirtualResolution = new Vector3(_virtualResolution, 1)};

            _artworkFactory = new ArtworkFactory(install, _container);
            _texmapFactory = new TexmapFactory(install, _container);
            _animationFactory = new AnimationFactory(install, _container);
            _gumpFactory = new GumpFactory(install, _container);
            _asciiFontFactory = new ASCIIFontFactory(install, _container);
            _unicodeFontFactory = new UnicodeFontFactory(install, _container);

            // register the renderer in the pipeline
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers) scene.Settings.GraphicsCompositor);

            compositor.Master.Renderers.Add(new ClearRenderFrameRenderer());
            compositor.Master.Renderers.Add(new SceneDelegateRenderer(RenderQuad));
        }
Пример #12
0
        /// <summary>
        /// Draw all text groups with SpriteBatch
        /// </summary>
        public override void Start()
        {
            // Create the SpriteBatch used to render them
            spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = new Vector3(virtualResolution, 1000) };

            centerVirtualPosition = new Vector2(virtualResolution.X * 0.5f, virtualResolution.Y * 0.5f);
            screenSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height);

            // Load fonts
            staticFont = Asset.Load<SpriteFont>("StaticFont");
            dynamicFont = Asset.Load<SpriteFont>("DynamicFont");
            boldFont = Asset.Load<SpriteFont>("BoldFont");
            italicFont = Asset.Load<SpriteFont>("ItalicFont");

            aliasedFont = Asset.Load<SpriteFont>("AliasedFont");
            antialiasedFont = Asset.Load<SpriteFont>("AntialiasedFont");
            clearTypeFont = Asset.Load<SpriteFont>("ClearTypeFont");

            japaneseFont = Asset.Load<SpriteFont>("JapaneseFont");
            timesNewRoman = Asset.Load<SpriteFont>("TimesNewRoman");
            headerFont = Asset.Load<SpriteFont>("HeaderFont");

            screenRenderers.Add(DrawIntroductionCategory);
            screenRenderers.Add(DrawStaticCategory);
            screenRenderers.Add(DrawDynamicCategory);
            screenRenderers.Add(DrawStyleCategory);
            screenRenderers.Add(DrawAliasCategory);
            screenRenderers.Add(DrawLanguageCategory);
            screenRenderers.Add(DrawAlignmentCategory);
            screenRenderers.Add(DrawAnimationCategory);

            // Add Graphics Layer
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers) scene.Settings.GraphicsCompositor);
            compositor.Master.Renderers.Add(delegateRenderer = new SceneDelegateRenderer(DrawFont));
        }
        // Complete the graphic pipeline, initialize texture data
        public override void Start()
        {
            // create the sprite batch used in our custom rendering function
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // insert the custom renderer in between the 2 camera renderer.
            var scene = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor);
            compositor.Master.Renderers.Insert(2, new SceneDelegateRenderer(RenderTexture));

            // Create and initialize the dynamic texture
            renderTexture = Texture.New2D(GraphicsDevice, RenderTextureSize, RenderTextureSize, 1, PixelFormat.B8G8R8A8_UNorm, usage: GraphicsResourceUsage.Dynamic);

            // Setup initial data in "SymmetricDefaultShape" to the texture
            for (var i = 0; i < SymmetricDefaultShape.Length; i += 2)
            {
                TogglePixel(SymmetricDefaultShape[i], SymmetricDefaultShape[i + 1]);
                if (SymmetricDefaultShape[i] != (RenderTextureSize - 1) - SymmetricDefaultShape[i])
                    TogglePixel((RenderTextureSize - 1) - SymmetricDefaultShape[i], SymmetricDefaultShape[i + 1]);
            }

            renderTexture.SetData(textureData);
        }
        protected override void InitializeCore()
        {
            base.InitializeCore();

            spriteBatch = new SpriteBatch(Context.GraphicsDevice) { VirtualResolution = new Vector3(1)};
        }