Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Hard Challenge - Moving images
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-10-2012, 11:33 PM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default 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
Reply With Quote
  #2  
Old 04-11-2012, 11:58 AM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default 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?
Reply With Quote
  #3  
Old 04-13-2012, 08:27 PM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default Re: Hard Challenge - Moving images

Quote:
Originally Posted by The Fat Controller View Post
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
Reply With Quote
  #4  
Old 04-14-2012, 01:24 PM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default Re: Hard Challenge - Moving images

Quote:
Originally Posted by lordzsolt View Post
I did it with the readimagefile command.
If you post your code up I might be able to help.
Reply With Quote
  #5  
Old 04-16-2012, 06:20 PM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default 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
Reply With Quote
  #6  
Old 04-16-2012, 08:46 PM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default 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.
Reply With Quote
  #7  
Old 04-17-2012, 11:13 AM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default 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
Reply With Quote
  #8  
Old 04-17-2012, 11:24 PM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default 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.
Reply With Quote
  #9  
Old 04-18-2012, 12:00 AM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default 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
Reply With Quote
  #10  
Old 04-18-2012, 01:53 AM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default Re: Hard Challenge - Moving images

Quote:
Originally Posted by lordzsolt View Post
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.
Reply With Quote
  #11  
Old 04-18-2012, 04:21 PM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default 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.
Reply With Quote
  #12  
Old 04-18-2012, 06:14 PM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default 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.
Reply With Quote
  #13  
Old 04-18-2012, 06:28 PM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default Re: Hard Challenge - Moving images

Quote:
Originally Posted by The Fat Controller View Post
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
Reply With Quote
  #14  
Old 04-18-2012, 08:42 PM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default Re: Hard Challenge - Moving images

Updated question: Is there any way to clear those buffers?
__________________

Skype: Lord_Zsolti
Reply With Quote
  #15  
Old 04-20-2012, 08:23 PM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default Re: Hard Challenge - Moving images

No problem, this old graphics stuff is interesting.

Quote:
Originally Posted by lordzsolt View Post
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.
Reply With Quote
  #16  
Old 04-24-2012, 09:20 AM
lordzsolt's Avatar
Guru
$5 USD Donor
 
Join Date: Jul 2008
Location: Behind You, Always behind you
Posts: 1,946
Send a message via MSN to lordzsolt Send a message via Yahoo to lordzsolt Send a message via Skype™ to lordzsolt
Default 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
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 02:32 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1