/// <summary> /// calling when screen size has changed. /// changes the sizes of camera and Hud when the screen size is changed. /// </summary> /// <param name="viewRect">new view area</param> public override void OnSize(Rectangle newRect) { base.OnSize(newRect); Viewport viewport = FrameworkCore.CurrentViewport; // Follow Camera ViewCamera followViewCamera = Viewer.GetViewCamera("Follow"); followViewCamera.Resize(0, viewport.X, viewport.Y, viewport.Width, viewport.Height); // Resizing Hud ResizeHud(); }
/// <summary> /// calling when screen size has changed. /// changes the sizes of camera and Hud when the screen size is changed. /// </summary> /// <param name="viewRect">new view area</param> public override void OnSize(Rectangle newRect) { base.OnSize(newRect); int playerCount = GameLevel.PlayerCountInLevel; Viewport viewport = FrameworkCore.CurrentViewport; // split-screen Camera ViewCamera followViewCamera = Viewer.GetViewCamera("Follow"); for (int i = 0; i < playerCount; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); int splitX = 0; int splitY = 0; int splitWidth = 0; int splitHeight = 0; // 1P viewport area if (i == 0) { splitX = 0; splitY = 0; } // 2P viewport area else if (i == 1) { splitX = 0; splitY = viewport.Height / playerCount; } splitWidth = viewport.Width; splitHeight = viewport.Height / playerCount; // Resizing camera followViewCamera.Resize(i, splitX, splitY, splitWidth, splitHeight); } // Resize Hud { int posX = 0, posY = 0, scaledWidth = 0, scaledHeight = 0, offsetY = 0; ViewCamera viewCamera = FrameworkCore.CurrentCamera; int viewCount = viewCamera.Count; float scaleFactor = 1.0f; if (GameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { scaleFactor = 0.8f; } // Scaling image size and positioning for screen resolution Vector2 sizeScale = new Vector2( (float)FrameworkCore.ViewWidth * scaleFactor / (float)ViewerWidth.Width1080, (float)FrameworkCore.ViewHeight * scaleFactor / (float)ViewerHeight.Height1080); Vector2 posScale = new Vector2( (float)FrameworkCore.ViewWidth * scaleFactor / (float)ViewerWidth.Width1080, (float)FrameworkCore.ViewHeight * scaleFactor / (float)ViewerHeight.Height1080); // if versus mode, apply width offset rate if (GameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { posScale.X *= 1.3f; } for (int i = 0; i < viewCount; i++) { Viewport view = viewCamera.GetViewport(i); offsetY = (int)view.Y; // kill score and condition score this.textKillScore[i].PosX = (int)(215 * posScale.X); this.textKillScore[i].PosY = (int)((float)view.Height * 0.68f) + offsetY; this.textKillConditionScore[i].PosX = (int)(300 * posScale.X); this.textKillConditionScore[i].PosY = (int)((float)view.Height * 0.76f) + offsetY; this.textKillScore[i].Scale = 1.6f; this.textKillConditionScore[i].Scale = 0.8f; float textScale = 1.4f * (float)FrameworkCore.ViewWidth / (float)ViewerWidth.Width720; this.textKillScore[i].Scale *= textScale; this.textKillConditionScore[i].Scale *= textScale; } // 1P image this.spriteObjHudVersus1P.SourceRectangle = new Rectangle( 82, 560, image1PWidth, image1PHeight); this.spriteObjHudVersus1P.ScreenRectangle = new Rectangle( (int)(FrameworkCore.ViewWidth * 0.05f), (int)(FrameworkCore.ViewHeight / 2 * 0.76f), (int)((float)image1PWidth * sizeScale.X), (int)((float)image1PHeight * sizeScale.Y)); // 2P image this.spriteObjHudVersus2P.SourceRectangle = new Rectangle( 532, 560, image1PWidth, image1PHeight); offsetY = (FrameworkCore.ViewHeight / 2); this.spriteObjHudVersus2P.ScreenRectangle = new Rectangle( (int)(FrameworkCore.ViewWidth * 0.05f), (int)((FrameworkCore.ViewHeight / 2 * 0.76f) + offsetY), (int)((float)image1PWidth * sizeScale.X), (int)((float)image1PHeight * sizeScale.Y)); this.spriteObjHudVersusWin.SourceRectangle = new Rectangle(108, 55, imageWinWidth, imageWinHeight); this.spriteObjHudVersusLose.SourceRectangle = new Rectangle(48, 370, imageLoseWidth, imageLoseHeight); if (this.isFinishedVersus) { for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); // You win if (RobotGameGame.VersusGameInfo.killPoint <= player.KillPoint) { scaledWidth = (int)((float)imageWinWidth * sizeScale.X); scaledHeight = (int)((float)imageWinHeight * sizeScale.Y); posX = (int)((FrameworkCore.ViewWidth / 2) - (scaledWidth / 2)); posY = (int)((FrameworkCore.ViewHeight / 2) - (scaledHeight / 2)); if (player.PlayerIndex == PlayerIndex.One) { posY -= FrameworkCore.ViewHeight / 4; } else if (player.PlayerIndex == PlayerIndex.Two) { posY += FrameworkCore.ViewHeight / 4; } this.spriteObjHudVersusWin.ScreenRectangle = new Rectangle( posX, posY, scaledWidth, scaledHeight); } // You lose else { scaledWidth = (int)((float)imageLoseWidth * sizeScale.X); scaledHeight = (int)((float)imageLoseHeight * sizeScale.Y); posX = (int)((FrameworkCore.ViewWidth / 2) - (scaledWidth / 2)); posY = (int)((FrameworkCore.ViewHeight / 2) - (scaledHeight / 2)); if (player.PlayerIndex == PlayerIndex.One) { posY -= FrameworkCore.ViewHeight / 4; } else if (player.PlayerIndex == PlayerIndex.Two) { posY += FrameworkCore.ViewHeight / 4; } this.spriteObjHudVersusLose.ScreenRectangle = new Rectangle(posX, posY, scaledWidth, scaledHeight); } } } // Resizing Hud ResizeHud(); } }