Click or drag to resize
SpriteControllerReplaceOriginalImage Method
Overload List
  NameDescription
Public methodReplaceOriginalImage
Notify the sprite controller that you have changed the background image on the PictureBox. Whatever background is on the picturebox is now used to draw all the sprites on.
Public methodCode exampleReplaceOriginalImage(Image)
Replace the image on which the sprites are drawn. Use this when you move to a new playing field, or want to have a different background
Examples
Replacing the background image is actually a lot more complex than you might imagine. Once you use the below code, it can be done without any problem. But you need to do it this way, or it just goofs up in a number of small ways. You need to tell the sprite controller that you are replacing the background image, and you need to change the image to that image as well.Because the Images are actually pointers to memory where the image sets, changes to one image will affect the other image.This goofs things up, so what we do is duplicate the image twice, and tell the sprite controller to use one of the copies and then set the background to be the other one of the two copies.Finally, we tell the picturebox to invalidate itself.That does everything that is needed.
C#
 void ReplaceBackground(Image NewBackground)
{
    if (MyController == null) return;
    if (NewBackground == null) return;

    Image OneImage = new Bitmap(NewBackground);
    MyController.ReplaceOriginalImage(OneImage);

    Image TwoImage = new Bitmap(NewBackground);
    pb_map.BackgroundImage = TwoImage;
    pb_map.Invalidate();
}
Top
See Also