I am coding a very basic side-scrolling game in C#, using Windows Forms.
I want to connect my game's levels with 'exit points'. When the player touches an exit point, a new form should be loaded immediately. How can I do this?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI am coding a very basic side-scrolling game in C#, using Windows Forms.
I want to connect my game's levels with 'exit points'. When the player touches an exit point, a new form should be loaded immediately. How can I do this?
Yes, it's feasible: if the player hits the trigger area, create the new form and position it appropriately and then close the old form (the order is relatively important here, because the default Windows Forms application driver, the Run
call, will terminate the application when the last form is closed so you always want to make sure at least one exists, or you want to change that Run
call).
For example, assuming you call a method of the current form called OnPlayerHitExit
when the player hits the exit area, you could:
void OnPlayerHitExit () {
var nextLevel = new FormContainingNextLevel();
nextLevel.Show();
Close();
}
That said, you shouldn't put each level in its own form. A form is a Win32 window, and closing one/opening a new one will be visible and noticeable to the player even if you spend time doing all the necessary hackery to get as close as possible to a seemless transition.
Instead, store your level data independently of the form itself (maybe in a Level
class) and when the player hits the trigger area, replacing the existing level data with new level data.