TiledLib.Camera.Update C# (CSharp) Méthode

Update() public méthode

Update the camera
public Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
Résultat void
        public void Update(GameTime gameTime)
        {
            // Clamp target to map/camera bounds
            ClampRect = new Rectangle((int)((Width / 2f) / Zoom), (int)((Height / 2f) / Zoom), (BoundsWidth) - (int)((Width / 2f) / Zoom), (BoundsHeight) - (int)((Height / 2f) / Zoom));

            Target.X = MathHelper.Clamp(Target.X, ClampRect.X, ClampRect.Width);
            Target.Y = MathHelper.Clamp(Target.Y, ClampRect.Y, ClampRect.Height);

            Position.X = MathHelper.Clamp(Position.X, ClampRect.X, ClampRect.Width);
            Position.Y = MathHelper.Clamp(Position.Y, ClampRect.Y, ClampRect.Height);

            if (shakeTime > 0)
            {
                shakeTime -= gameTime.ElapsedGameTime.TotalMilliseconds;
                shakeOffset = new Vector2((int)Helper.RandomFloat(-shakeAmount, shakeAmount), (int)Helper.RandomFloat(-shakeAmount, shakeAmount));
            }
            else shakeOffset = Vector2.Zero;

            // Move camera toward target
            Position = Vector2.Lerp(Position, Target, Speed);

            CameraMatrix = Matrix.CreateTranslation(-Position.X + shakeOffset.X, -Position.Y + shakeOffset.Y, 0) *
                           Matrix.CreateScale(Zoom) *
                           Matrix.CreateRotationZ(Rotation) *
                           Matrix.CreateTranslation(Width / 2f, Height / 2f, 0);
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            AudioController.LoadContent(content);

            //gameFont = content.Load<SpriteFont>("menufont");

            lightingEngine.LoadContent(content, ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch);

            enemyController = new EnemyController();
            enemyController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine);
            particleController = new ParticleController();
            particleController.LoadContent(content);
            projectileController = new ProjectileController();
            projectileController.LoadContent(content);
            itemController = new ItemController();
            itemController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine);
            vehicleController = new VehicleController();
            vehicleController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine);

            gameMap = content.Load<Map>("map/map");

            gameHud = new Hud();
            gameHud.LoadContent(content);

            mapFog = new bool[gameMap.Width, gameMap.Height];

            ThreadPool.QueueUserWorkItem(new WaitCallback(GenerateTerrainAsync));

            gameHero = new HeroDude(gameMap.HeroSpawn);
            gameHero.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine);

            gameCamera = new Camera(ScreenManager.GraphicsDevice.Viewport, gameMap);
            gameCamera.ClampRect = new Rectangle(0, 0, gameMap.Width * gameMap.TileWidth, gameMap.Height * gameMap.TileHeight);
            gameCamera.ZoomTarget = 1f;
            //gameCamera.Position = gameHero.Position - (new Vector2(ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height) / 2);
            gameCamera.Position = gameHero.Position;
            gameCamera.Target = gameCamera.Position;
            gameCamera.Update(ScreenManager.GraphicsDevice.Viewport.Bounds);

            //cameraLightSource.Type = LightSourceType.Spot;
            //lightingEngine.LightSources.Add(cameraLightSource);

            minimapRT = new RenderTarget2D(ScreenManager.GraphicsDevice, 200, 200);

            crosshairTex = content.Load<Texture2D>("crosshair");
            mapIcons = content.Load<Texture2D>("mapicons");

            //lightSource1 = new LightSource(ScreenManager.GraphicsDevice, 600, LightAreaQuality.Low, new Color(1f, 1f, 1f), BeamStencilType.Wide, SpotStencilType.None);

            //lightingEngine.LightSources.Add(lightSource1);

            ScreenManager.Game.ResetElapsedTime();
        }
All Usage Examples Of TiledLib.Camera::Update