protected override async Task LoadContent() { await base.LoadContent(); // sets the virtual resolution areaSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); // Creates the camera CameraComponent.UseCustomProjectionMatrix = true; CameraComponent.ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(new Vector3(areaSize, 200)); // Load assets groundSprites = Asset.Load <SpriteGroup>("GroundSprite"); ballSprite1 = Asset.Load <Texture>("Sphere1"); ballSprite2 = Asset.Load <Texture>("Sphere2"); ball = Asset.Load <Entity>("Ball"); // create fore/background entities foreground = new Entity(); background = new Entity(); foreground.Add(new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = groundSprites }, CurrentFrame = 1 }); background.Add(new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = groundSprites }, CurrentFrame = 0 }); Scene.AddChild(ball); Scene.AddChild(foreground); Scene.AddChild(background); spriteComponent = ball.Get(SpriteComponent.Key); transfoComponent = ball.Get(TransformComponent.Key); transfoComponent.Position.X = areaSize.X / 2; transfoComponent.Position.Y = areaSize.Y / 2; var decorationScalings = new Vector3(areaSize.X, areaSize.Y, 1); background.Get(TransformComponent.Key).Scale = decorationScalings; foreground.Get(TransformComponent.Key).Scale = decorationScalings; background.Get(TransformComponent.Key).Position = new Vector3(0, 0, -1); foreground.Get(TransformComponent.Key).Position = new Vector3(0, areaSize.Y, 1); SpriteAnimation.Play(spriteComponent, 0, spriteComponent.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.LoopInfinite, 30); }
protected override async Task LoadContent() { await base.LoadContent(); // For now lets set our virtual resolution the same as the actual resolution // But we may want to hard code this to some value VirtualResolution = new Vector3(GraphicsDeviceManager.PreferredBackBufferWidth, GraphicsDeviceManager.PreferredBackBufferHeight, 20f); // Create our camera, cause yay :D cameraEntity = new Entity("Camera") { new CameraComponent() { UseProjectionMatrix = true, ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(VirtualResolution) } }; // Create our player entitiy var playerEntity = new Entity() { new SpriteComponent() { SpriteGroup = Asset.Load <SpriteGroup>("Temp"), CurrentFrame = 0 }, new TransformationComponent() { Translation = new Vector3(100, 100, 0) } }; // Make it so the engine knows about it Entities.Add(playerEntity); // A wrapper class for the entity that actual handles our stuff, // Yeah, components all the way might of been better, but for now this'll do, just // following JumpyJets example :P player = new Player(playerEntity, Input); LevelReader reader = new LevelReader("/data/TestMap.json"); reader.Read(); // Create our level var platforms = Asset.Load <SpriteGroup>("TileSetTest"); level = new Level(new Size2(20, 11)); for (int x = 0; x < 20; x++) { level.SetTile(x, 0, new Tile() { Sprite = platforms[0] }); level.SetTile(x, 10, new Tile() { Sprite = platforms[0] }); } level.SetTile(19, 9, new Tile() { Sprite = platforms[0] }); level.BuildTileData(); // Set up the rendering pipeline CreatePipeline(); gameHud = new UiGameHud(Services); gameHud.LoadContent(); // Kick off our update loop Script.Add(UpdateLoop); }
protected override async Task LoadContent() { await base.LoadContent(); // sets the virtual resolution areaSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); VirtualResolution = new Vector3(areaSize.X, areaSize.Y, 1000); // Creates the camera var cameraComponent = new CameraComponent { UseProjectionMatrix = true, ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(new Vector3(areaSize, 200)) }; var camera = new Entity("Camera") { cameraComponent }; // Create Main pass var mainPipeline = RenderSystem.Pipeline; mainPipeline.Renderers.Add(new CameraSetter(Services) { Camera = cameraComponent }); mainPipeline.Renderers.Add(new RenderTargetSetter(Services) { ClearColor = Color.LightBlue }); mainPipeline.Renderers.Add(new SpriteRenderer(Services)); // Load assets groundSprites = Asset.Load <SpriteGroup>("GroundSprite"); ballSprite1 = Asset.Load <SpriteGroup>("BallSprite1"); ballSprite2 = Asset.Load <SpriteGroup>("BallSprite2"); ball = Asset.Load <Entity>("Ball"); // create fore/background entities foreground = new Entity(); background = new Entity(); foreground.Add(new SpriteComponent { SpriteGroup = groundSprites, CurrentFrame = 1 }); background.Add(new SpriteComponent { SpriteGroup = groundSprites, CurrentFrame = 0 }); Entities.Add(camera); Entities.Add(ball); Entities.Add(foreground); Entities.Add(background); spriteComponent = ball.Get(SpriteComponent.Key); transfoComponent = ball.Get(TransformationComponent.Key); transfoComponent.Translation.X = areaSize.X / 2; transfoComponent.Translation.Y = areaSize.Y / 2; var backgroundSpriteRegion = background.Get(SpriteComponent.Key).SpriteGroup.Images[0].Region; var decorationScalings = new Vector3(areaSize.X / backgroundSpriteRegion.Width, areaSize.Y / backgroundSpriteRegion.Height, 1); background.Get(TransformationComponent.Key).Scaling = decorationScalings; foreground.Get(TransformationComponent.Key).Scaling = decorationScalings; background.Get(TransformationComponent.Key).Translation = new Vector3(0, 0, -1); foreground.Get(TransformationComponent.Key).Translation = new Vector3(0, areaSize.Y, 1); SpriteAnimation.Play(spriteComponent, 0, spriteComponent.SpriteGroup.Images.Count - 1, AnimationRepeatMode.LoopInfinite, 30); }