/// <summary> /// Provides correct information about the window to the rest of the application /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void updateBoundsOnChange(object sender, EventArgs e) { zeroedWindow = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height); center = new Vector2(zeroedWindow.Width / 2, zeroedWindow.Height / 2); //set rendertargets RenderTargetManager.sizeRenderTargets(); }
private void drawMainGame(GameTime gameTime, int shaderNum) { RenderTargetManager.setRenderTarget(RenderTargetManager.framePreRender); //background colour: Purple! GraphicsDevice.Clear(Color.Purple); //New updated real draw calls //which does not rely on spaghetti spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); //the blocks are in the waaaaay back. //if buffered draw is used, they *must* be the first thing drawn. world.draw(spriteBatch); foreach (Particle particle in Particle.active) { particle.draw(spriteBatch); } //NPCs are behind the player foreach (NPC npc in NPC.Active) { npc.draw(spriteBatch); } //Due to immediate, draw back to front currentPlayer.draw(spriteBatch); //UI & projectiles are in front foreach (Projectile p in Projectile.active) { p.draw(spriteBatch); } //item draw foreach (ItemInWorld item in ItemInWorld.active) { item.draw(spriteBatch); } //UI over all. IGUI.draw(); spriteBatch.End(); RenderTargetManager.unsetRenderTarget(); //draw the rendered scene to the screen. spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp); //Everything is shader! mainShader.CurrentTechnique.Passes[shaderNum].Apply(); //Draw everything. spriteBatch.Draw(RenderTargetManager.framePreRender, zeroedWindow, Color.White); spriteBatch.End(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { //Add methods to the size change Window.ClientSizeChanged += updateBoundsOnChange; //temporary, add the player. //players[thisPlayer] = Player.load("player.ghb") ?? new Player(new PlayerInputController(), Vector2.Zero); //Set window's title. Window.Title = "Yaritakunai"; //Set the bounds to the initial value. updateBoundsOnChange(null, null); //Assigned to a bool as it is the status of if there is a settings.json. //If there is not, we go to the language select screen and use the default cursor colour. (etc, etc) bool settingsLoaded = Settings.init(); //perfrom initialization Input.init(); Camera.init(); Player.init(); UIS.init(); Task.Run(() => IME.init()); BGMPlayer.init(); Item.init(); Projectile.init(); #if FORCE_RESET_SETTINGS settingsLoaded = false; Settings.defaults(); #endif if (settingsLoaded) { switchScreenTo(screens.title); } Settings.makeSureSettingsDirectoriesExist(); base.Initialize(); RenderTargetManager.init(GraphicsDevice); updateBoundsOnChange(null, null); }
/// <summary> /// Draws a frame of the game to a rendertarget. /// </summary> /// <param name="screen"></param> /// <param name="target"></param> public void drawFrameToRenderTarget(screens screen, RenderTarget2D target) { //save information & set to values screens pastScreen = currentScreen; currentScreen = screen; bool cursorShown = isCursorDrawn; isCursorDrawn = false; bool controllerCursorShown = isPsuedoCursorDrawn; isPsuedoCursorDrawn = false; //Set to provided target and draw. RenderTargetManager.setRenderTarget(target); Draw(lastDrawTime); //Reset graphics device. RenderTargetManager.unsetRenderTarget(); //Reset screen and cursor. currentScreen = pastScreen; isCursorDrawn = cursorShown; isPsuedoCursorDrawn = controllerCursorShown; }