 |

04-10-2012, 11:33 PM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Hard Challenge - Moving images
I've come up to possibly my hardest hard challenge.
Basically, I have a background and I have an image that follows the cursor.
I managed to do this by constantly printing the background image to the screen, then printing the image that's following the cursor on it. But this causes the image to keep blinking (obviously).
Is there any other way to do this?
__________________

Skype: Lord_Zsolti
|

04-11-2012, 11:58 AM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
How are you doing the drawing?
Are you using double buffering? Are you sure the images are being drawn every frame?
|

04-13-2012, 08:27 PM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
Quote:
Originally Posted by The Fat Controller
How are you doing the drawing?
Are you using double buffering? Are you sure the images are being drawn every frame?
|
I did it with the readimagefile command.
__________________

Skype: Lord_Zsolti
|

04-14-2012, 01:24 PM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
Quote:
Originally Posted by lordzsolt
I did it with the readimagefile command.
|
If you post your code up I might be able to help.
|

04-16-2012, 06:20 PM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
Code:
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);
}
This is the fragment that interests us:
putimage(0,0,buffer2,0);
readimagefile("Kepek/Battle/Troops/Command_Center.GIF",mx-62,my-62,mx+62,my+62)
As you can see, every time I move the cursor, I redraw the the background and draw the airplane on it. This causes the pixels where the airplane is located to keep flashing (obviously, since it can't paint fast enough). I'd need a whole new way of doing this.
__________________

Skype: Lord_Zsolti
|

04-16-2012, 08:46 PM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
Quote:
|
As you can see, every time I move the cursor, I redraw the the background and draw the airplane on it. This causes the pixels where the airplane is located to keep flashing (obviously, since it can't paint fast enough). I'd need a whole new way of doing this.
|
Copy the background image into a single buffer, then overwrite parts of that buffer with the airplane images. That way you will only have to call putimage on that buffer, and avoid the flashing problem.
|

04-17-2012, 11:13 AM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
What what? Yeah, that sounds quite smart, though what command do you use to write on the buffer? Could you write that part of the code that does this?
__________________

Skype: Lord_Zsolti
|

04-17-2012, 11:24 PM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
Sorry I don't want to write code. However if it's WinBGIm you're using, then this might help:
http://www.cs.colorado.edu/~main/bgi/doc/
Alternatively you could try enabling double buffering by passing true for the dbflag parameter in your initwindow call, and calling swapbuffers() at the end of your main loop... I think that would also fix the problem.
|

04-18-2012, 12:00 AM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
Ok, I've tried digging as deep as I can, but I still can't find which function to use for writing on the buffer.
Correct me if I'm wrong, but even if I was to do double buffering, I'd still need to write on the second buffer.
__________________

Skype: Lord_Zsolti
|

04-18-2012, 01:53 AM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
Quote:
Originally Posted by lordzsolt
Ok, I've tried digging as deep as I can, but I still can't find which function to use for writing on the buffer.
|
I've never used these old graphics functions before, so I can't say for sure whether you can do what I was describing back there. However...
Quote:
|
Correct me if I'm wrong, but even if I was to do double buffering, I'd still need to write on the second buffer.
|
If you enable double buffering, then I think the window will set up two internal buffers (these are unrelated to buffer1 and buffer2 in your own code).
One of these internal buffers will be the one you draw everything onto. The other buffer is what is shown on the screen.
If you look at the initwindow function in the documentation, you'll see that there are extra optional parameters.
So, see this here, call it like this to enable double buffering:
Code:
initwindow(yourwidth, yourheight, "title", 0, 0, true, true)
And call swapwindow() when you've done the drawing and want to display whatever on the screen.
Last edited by The Fat Controller : 04-18-2012 at 01:54 AM.
|

04-18-2012, 04:21 PM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
OMG YOU'RE AWESOME!!!
It's working really well!
Is there any way to turn off double buffering? Since I only need it a part of the program.
I've though about doing it somewhat like this. swapbuffers () can be switched with
Code:
int oldv = getvisualpage( );
int olda = getactivepage( );
setvisualpage(olda);
setactivepage(oldv);
So once I'm done with double buffering, I'll merge the visualpage and activepage. Then when I need to turn double buffering off, I'll split them. Do you think this could work? I'll be testing it in a few hours.
__________________

Skype: Lord_Zsolti
Last edited by lordzsolt : 04-18-2012 at 04:50 PM.
|

04-18-2012, 06:14 PM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
Awesome, so the flashing is gone? Glad to help
I'd recommend using double buffering for all the drawing unless there's a reason not to. But see what works for you.
|

04-18-2012, 06:28 PM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
Quote:
Originally Posted by The Fat Controller
Awesome, so the flashing is gone? Glad to help
I'd recommend using double buffering for all the drawing unless there's a reason not to. But see what works for you.
|
OMG OMG OMG YOU'RE AWESOME!!!!!!!!!!!
I managed to get it done and it works perfectly and it looks amazing!!!!!
As for why I'd like to turn off double buffering, is that it turns to be useless after I'm done with this part, plus when I'm done with placing all the ships, I need to save the contects of a portion of the screen and print it to the new one (background when placing ships is different then when you're playing), and for some reason it messed up, and I felt like it's simpler to me this way (when I need double buffering, I just use two buffers, and when I don't, I just merg the active and visual pages while saving one of them for later use). But this doesn't make any difference in the way the viewer sees the game.
Once again, you're mega awesome and thanks for sticking to me for nearly a week now.
__________________

Skype: Lord_Zsolti
|

04-18-2012, 08:42 PM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
Updated question: Is there any way to clear those buffers?
__________________

Skype: Lord_Zsolti
|

04-20-2012, 08:23 PM
|
 |
Apprentice
|
|
Join Date: Aug 2007
Posts: 998
|
|
Re: Hard Challenge - Moving images
No problem, this old graphics stuff is interesting.
Quote:
Originally Posted by lordzsolt
Updated question: Is there any way to clear those buffers?
|
Looking at the documentation, I think either cleardevice() or clearviewport() will do that. You might need to set the colour to clear to by using setbkcolor() first.
You would clear the offscreen buffer at the start of every new frame, before you begin drawing.
|

04-24-2012, 09:20 AM
|
 |
Guru
|
|
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
|
|
Re: Hard Challenge - Moving images
Ok, decided to follow you advice and use two buffers during the whole program since I've found what the problem was.
__________________

Skype: Lord_Zsolti
|
 |
|