Exemple #1
0
        public void Begin(SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode stateMode, Matrix transformMatrix)
        {
            //to respect order Begin/Draw/end
            if (isRunning)
            {
                throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
            }

            if (stateMode == SaveStateMode.SaveState)
            {
                saveState = new StateBlock(this.GraphicsDevice);
            }


            spriteBlendMode = blendMode;
            this.sortMode   = sortMode;
            if (sortMode == SpriteSortMode.Immediate)
            {
                applyGraphicsDeviceSettings();
            }
            isRunning = true;
        }
Exemple #2
0
        /// <summary>Updates the Xen Application (if the game uses fixed time steps) and then calls the application to draw</summary>
        public override void Draw(GameTime gameTime)
        {
            if (this.stateBlock == null)
            {
                this.stateBlock = new StateBlock(game.GraphicsDevice);
            }

            if (game.IsFixedTimeStep && UpdateEvent != null)
            {
                UpdateEvent(gameTime, this);
            }

            this.stateBlock.Capture();

            if (DrawEvent != null)
            {
                DrawEvent(gameTime, this);
            }

            this.stateBlock.Apply();

            base.Draw(gameTime);
        }
        protected override void Initialize()
        {
            content = new ContentManager(Services, "Content");

            // Load all trees in the Content/Trees folder
            string[] files = Directory.GetFiles("Content/Trees", "*.xnb", SearchOption.TopDirectoryOnly);
            foreach (string filename in files)
            {
                string assetName = filename.Substring("Content/".Length, filename.Length - "Content/.xnb".Length);
                Profiles.Add(content.Load<TreeProfile>(assetName));
                ProfileNames.Add(Path.GetFileName(assetName));
            }
            profileIndex = 0;

            // Create the wind animator
            wind = new WindStrengthSin();
            animator = new TreeWindAnimator(wind);

            // Create the ground plane and an effect for it
            groundPlane = new Quad(GraphicsDevice, 10000, 10000);
            groundEffect = new BasicEffect(GraphicsDevice, new EffectPool());
            groundEffect.Texture = content.Load<Texture2D>("Textures/Grass");
            groundEffect.TextureEnabled = true;

            // Create a camera
            Camera = new Camera();
            Camera.Position = new Vector3(4000, 4000, 4000);
            Camera.Target = new Vector3(0, 2000, 0);
            Camera.AspectRatio = GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height;

            CameraOrbitAngle = 0.0f;
            CameraPitchAngle = -10.0f;
            CameraDistance = 5000.0f;

            // Enable mipmaps
            GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Linear;

            // Store the initial renderstate
            block = new StateBlock(GraphicsDevice);
            block.Capture();

            Initialized = true;

            UpdateTree();

            Application.Idle += new EventHandler(Application_Idle);
        }