|
displaying and clearing a bitmap |
red-dragon
Member #7,722
August 2006
|
Hey everyone,
So, when I run this and right-click over and over, most of the time, the image appears where I've right clicked. Then a few times it disappears. Remember, goal is to right-click 1: image appears; right-click2: image disappears, and so on. So what obvious thing am I messing up with? |
HardTranceFan
Member #7,317
June 2006
|
From first glances: at the end of your "else if(mouse_b & 2)" section, put a "while (mouse_b & 2);". You're not waiting for the mouse button to go up, and so the code is repeatedly run while you press the right mouse button. Jeroen [edit]
Sorry, at work at the moment, so I can't determine if the code is 100% correct. -- |
sj971059
Member #7,689
August 2006
|
|
HardTranceFan
Member #7,317
June 2006
|
Hehehe. Ta for the correction. My C++ syntax is still lacking. Jeroen -- |
red-dragon
Member #7,722
August 2006
|
hey again both of you! Of course, your explanation makes sense. I'm trying to make changes like you've stated. I'm declaring bool rmb_down = false right after I do exist so that it is global. However, I keep getting this stubborn errors: Why does it complain about using a bool and false..? P.S. I think I tried to use exist as a bool and I was getting same errors. |
Ceagon Xylas
Member #5,495
February 2005
|
Could you post your new code? |
LennyLen
Member #5,313
December 2004
|
Quote: Why does it complain about using a bool and false..? You are compiling as C++, and not just C, right?
|
red-dragon
Member #7,722
August 2006
|
Lenny, |
LennyLen
Member #5,313
December 2004
|
Quote: I believe it is C. Bool is a C++ only type. You can implement a similar type in C using enumerations though. typedef enum { FALSE, TRUE } bool;
|
Jakub Wasilewski
Member #3,653
June 2003
|
Actually, C99 has bool, amongst other types that were formerly C++ only. Not that his compiler seems to support C99. --------------------------- |
KnightWhoSaysNi
Member #7,339
June 2006
|
int draw_bitmap() { BITMAP *ship = load_bitmap("spaceship.bmp", NULL); mx = mouse_x; my = mouse_y; masked_blit(ship, screen, 0, 0, mx, my, 64, 64); } I think this might keep causing your program to take up more and more memory. You only have to load the bitmap once, not every time you use it. Once you are done with it you have to free it. |
Ceagon Xylas
Member #5,495
February 2005
|
Don't forget to delete your pointer have you're done with it... Which, if you were going to keep doing it this way, then you'd need int draw_bitmap() { BITMAP *ship = load_bitmap("spaceship.bmp", NULL); mx = mouse_x; my = mouse_y; masked_blit(ship, screen, 0, 0, mx, my, 64, 64); destroy_bitmap(ship); } Otherwise destroy_bitmap() at the end of your program. =] |
red-dragon
Member #7,722
August 2006
|
hey guys, when I right-click, all is well. say I just right-click 3 times and the image appears on screen, then left-click. this gets rid of the image (which it shouldn't!). then if you right-click, it doesn't bring up the image till you right-click once more. what is with that...? Other than this little thing, it works. I'd just like to know what's going on. TIA! |
Ceagon Xylas
Member #5,495
February 2005
|
We'll have to see your code again probably. |
|