|
Bitmaps get confused |
James Stanley
Member #7,275
May 2006
|
I have some code that creates some images for buttons on a menu screen. What seems to happen is one of the buttons I make gets given the same memory position as the menu background. Here's the relevant code: menu = load_bitmap("menu.tga", NULL); play[1] = create_bitmap(300, 40); play[2] = create_bitmap(300, 40);//THIS IS THE LINE rectfill(play[1], 0, 0, 300, 40, pink); rectfill(play[2], 0, 0, 300, 40, darkblue); textout_centre_ex(play[1], myfont, "Play", 150, 0, darkblue, -1); textout_centre_ex(play[2], myfont, "Play", 150, 0, pink, -1); mask_image(play[1], pink); //I wrote mask_image. mask_image(play[2], pink); On the line marked THIS IS THE LINE, if I comment the whole line out, the code compiles fine, and all the drawing functions performed on play[2] get drawn to my menu background, if I don't comment it out, my menu background turns into the picture of a button. These aren't the final buttons, they look horrible, they're just for testing. I was wondering if anybody knew why this was happening or knew how to fix it, or has ever experienced it. EDIT: |
count
Member #5,401
January 2005
|
Quote: These aren't the final buttons, they look horrible, they're just for testing. We can't see them. From your code we can just see, that you create two bitmaps with a size of 300*40. Then you call your function which we can't see. Actually we don't know what you are doing. The problem is probably in your function. So show it
|
James Stanley
Member #7,275
May 2006
|
Sure, here's my menu loop. There are actually more buttons than that, but I thought that was adequate. 1 is for Not Selected, 2 is for Selected.
I wrote those other functions to go in my useful.cpp file. It's to reduce the amount of code I have to type. I know I haven't got the selection started at all yet, I'm having trouble with drawing the things, never mind selecting them. Never had this before, though... EDIT: void mask_image(BITMAP *bmp, int maskcol) { int x, y; for (y = 0; y < bmp->h+1; y++) { for (x = 0; x < bmp->w+1; x++) { if (getpixel(bmp, x, y) == maskcol) putpixel(bmp, x, y, bitmap_mask_color(bmp)); } } } It's just so that it's easier for me to load bitmaps with pink as the background and stuff like that. I dunno... EDIT2: |
count
Member #5,401
January 2005
|
edit Quote: What seems to happen is one of the buttons I make gets given the same memory position as the menu background.
What do you mean with this?
|
Kauhiz
Member #4,798
July 2004
|
What does the mask_image function look like/do? --- |
James Stanley
Member #7,275
May 2006
|
Masks the image with the colour specified. It's to simplify the process of getting invisible. It doesn't seem to work for this project. It's worked in my others. You can see what happens in the attachment to my previous post. Whenever I draw something to play[2], it goes to menu. |
count
Member #5,401
January 2005
|
Quote: You can see what happens in the attachment to my previous post. Whenever I draw something to play[2], it goes to menu. Ah, missed that. sorry. Does this only happen with "play"?
|
James Stanley
Member #7,275
May 2006
|
Which? The menu loop? That's it. The bit that says while(!key[KEY_ESC])
|
Kauhiz
Member #4,798
July 2004
|
Hey, wait a sec! Quote:
play[1] = create_bitmap(300, 40); If you declare that as BITMAP *play[2], then it should be play[0] = create_bitmap(300, 40); play[1] = create_bitmap(300, 40);//THIS IS THE LINE That would explain it... --- |
James Stanley
Member #7,275
May 2006
|
Oh. Really? Whoops. |
count
Member #5,401
January 2005
|
Oh, yes! It's an array overflow.
|
|