Modifying the contents of the buffer

I've been working on a simple game for my thesis, and I would like to improve it, and this simple change could mean a whole lot.

Basically, I'm using a picture as background, then I will be placing 4 ships on it. (Obviously, after placing one of the ships, when I want to place the second one, the first must stay at where I've placed it, which is why I'm using the buffer, to hold my image).

Now, when I'm in the process of placing a ship, it will be following my cursor. So I first place the image from the buffer ( with "putimagefile"), and then add the ship onto it (with "readimagefile"). This causes the pixels where the ships is to keep flashing (obviously, since it's painting one image, then another one).

So to solve this problem, I would need to put the ship on the image in the buffer instead of the screen, and then displaying the contents of the buffer. After searching for almost a week now, I've come here to find a solution. Hope somebody is kind enough to help me.



He's that section of the game:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
readimagefile("Kepek/Battle/BattleBG_Deploy.JPG",0,0,x,y);
    //Saving the background
    int size=imagesize (0,0,x,y);
    void* buffer1=malloc(size); //Alapkepernyo repulok nelkul
    void* buffer2=malloc(size);
    getimage(0,0,x,y,buffer1);
    //Showing the airplanes
    readimagefile("Kepek/Battle/Troops/Command_Center.GIF",535,318,659,442);
    readimagefile("Kepek/Battle/Troops/Scorpion.GIF",535,463,659,587);
    readimagefile("Kepek/Battle/Troops/Hellion.GIF",535,610,659,734);
    readimagefile("Kepek/Battle/Troops/Cannon.GIF",535,755,659,879);
    int place=0; // Number of planes deployed.
    cx=-1;
    cy=-1;
    bool run=true;
    do
    {
        getmouseclick(WM_LBUTTONDOWN,cx,cy);
        if (cx>535 && cy>318 && cx<659 && cy<442 && place!=4) // Clicked command center
        {
            putimage(0,0,buffer1,0);
            readimagefile("Kepek/Battle/Troops/Scorpion.GIF",535,463,659,587);
            readimagefile("Kepek/Battle/Troops/Hellion.GIF",535,610,659,734);
            readimagefile("Kepek/Battle/Troops/Cannon.GIF",535,755,659,879);
            getimage(0,0,x,y,buffer2);
            mx2=-1;
            my2=-1;
            do
            {
                mx=mousex();
                my=mousey();
                if (mx2!=mx || my2!=my)
                {
                    putimage(0,0,buffer2,0);
                    readimagefile("Kepek/Battle/Troops/Command_Center.GIF",mx-62,my-62,mx+62,my+62);
                }


That part that really interests us is:
1
2
putimage(0,0,buffer2,0);
readimagefile("Kepek/Battle/Troops/Command_Center.GIF",mx-62,my-62,mx+62,my+62)

As here is where I would need to change the contents of "buffer2".



I would really like, if someone could write and example code, since I'm still at a basic level on programming :(
Managed to work around it by turning on and off double buffering.
Topic archived. No new replies allowed.