/// <summary> /// Free any resources allocated for the panel. /// </summary> public void Dispose() { if (bmp != null) { bmp.Dispose(); } }
public virtual void Dispose() { if (_bitmap != null) { _bitmap.Dispose(); _bitmap = null; } }
public void Release() { if (_image != null) { _image.Dispose(); _image = null; } }
/// <summary> /// Release the resources allocated for the image. /// </summary> public void Unload() { if (bmp != null) { bmp.Dispose(); bmp = null; } }
/// <summary> /// Clean up any memory allocated by the bitmap object. /// </summary> public void Dispose() { if (!allocated) { return; } if (bmp != null) { bmp.Dispose(); } }
public static IBitmap AddLayer(this IBitmap bitmap, IBitmap layer, int left = 0, int top = 0, bool dispose = false) { if (layer == null) { return(bitmap); } AddLayer(bitmap, layer.Bitmap, left, top, false); if (dispose) { layer.Dispose(); } return(bitmap); }
/// <summary> /// Start the game. This method loads the game resources and /// runs the main game loop. /// </summary> public void Run() { // Load and validate the splash screen splash = graphics.CreateBitmap(GetFullPath(@"Data\Splash\splash.bmp"), false); Debug.Assert(splash != null, "GameMain.Run: Failed to initialized splash screen"); Debug.Assert(splash.Width <= graphics.ScreenWidth && splash.Height <= graphics.ScreenHeight, "GameMain.Run: Splash screen has invalid dimensions"); // Load the game ui now because it has font information that is // needed for drawing the 'Loading...' tag DataSet dsUI = new DataSet(); Debug.Assert(dsUI != null, "GameMain.LoadLevel: Failed to initialize UI DataSet"); dsUI.Locale = CultureInfo.InvariantCulture; // Load the ui xml file dsUI.ReadXml(GetFullPath(@"Data\UI\ui.xml")); // Load the resources specified in the xml file ui = new UserInterface(dsUI, graphics, level); Debug.Assert(ui != null, "GameMain.LoadLevel: Failed to initialize UI"); // Set the current update method as the splash screen updater update = new UpdateDelegate(UpdateSplash); // Loop until the game is done while (!done) { // Switch the update delegate if a switch was requested. switch (mode) { case ModeSwitch.UpdateLevel: gi.ClearKeyPresses(); update = new UpdateDelegate(UpdateLevel); numFrames = 0; secondsElapsedForCurrentFrames = 0; break; case ModeSwitch.UpdateCountdown: intro.Dispose(); intro = null; level.Update(gi); update = new UpdateDelegate(UpdateCountdown); break; case ModeSwitch.UpdateIntro: LoadLevel(); update = new UpdateDelegate(UpdateIntro); splash.Dispose(); splash = null; break; } mode = ModeSwitch.None; // Store the tick at which this frame started Int64 startTick = sw.CurrentTick(); // Check if the user pressed the exit key if (gi.KeyPressed((int)gi.HardwareKeys[Player.ButtonMap()[ (int)Player.Buttons.Quit]])) { done = true; } else if (levelLoaded && (level.Done || gi.KeyPressed( (int)gi.HardwareKeys[Player.ButtonMap()[ (int)Player.Buttons.ResetLevel]]))) { Reset(); Application.DoEvents(); continue; } // Update the game update(); // Check for pending events from the OS Application.DoEvents(); // Lock the framerate... Int64 deltaMS = sw.DeltaTimeMilliseconds(sw.CurrentTick(), startTick); Int64 minMS = (Int64)(1000.0F * MinSecondsPerFrame); Int64 maxMS = (Int64)(1000.0F * MaxSecondsPerFrame); // Check if the frame time was fast enough if (deltaMS <= minMS) { // Loop until the frame time is met do { if (gi.KeyPressed((int)gi.HardwareKeys[ Player.ButtonMap()[(int)Player.Buttons.Quit]])) { done = true; break; } // Thread.Sleep(0); Application.DoEvents(); deltaMS = sw.DeltaTimeMilliseconds(sw.CurrentTick(), startTick); } while (deltaMS < minMS); } // Increment the number of frames numFrames++; // Increment the overall time for these frames if (deltaMS < maxMS) { secondsElapsedForCurrentFrames += deltaMS / 1000.0F; } else { secondsElapsedForCurrentFrames += maxMS / 1000.0F; } // Make sure enough time has elapsed since the last check if (level != null && secondsElapsedForCurrentFrames > level.FrameRateCheckRate) { currentSecondsPerFrame = secondsElapsedForCurrentFrames / numFrames; numFrames = 0; secondsElapsedForCurrentFrames = 0; } } }