![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
How do I make the background color 0, etc |
SonShadowCat
Member #1,548
September 2001
![]() |
Ok, now I have this background which has some terrain with a building on it. I want the background to be 0 so my pixel doesnt collide with it and destroy it. One more question, why doesnt this code work? It should blit the pixels to the screen, delete the array and then draw a new set of pixels right? ty, sorry for being such an idiot -.- |
ReyBrujo
Moderator
January 2001
![]() |
Quote: blit( bomb[a]->picture, foreground, 0, 0, bomb[a]->x, bomb[a]->y, 1, 1); Hmm... you are blitting a picture which is 1x1? If picture is a color (int), you should use putpixel(foreground, bomb[a]->x, bomb[a]->y, bomb[a]->picture). If it is a bitmap... hmm... a 1x1 bitmap is a waste of memory. RB -- |
SonShadowCat
Member #1,548
September 2001
![]() |
For a program this trivial im not worried about saving memory. |
Plucky
Member #1,346
May 2001
![]() |
I see no reason to delete array of bomb[] in your code. What you're doing is creating the bombs (elsewhere), moving it one frame, check for collision, displaying it, blowing the bomb class variables away, creating a new set that gets initialized to the starting point (if initialized at all), moving it one frame, check for collision, etc. The bombs won't move because your replacing the bombs with a fresh set of bombs still at the starting line every frame. What you seem to want to do is erase graphically where the bombs used to be. Just store their previous locations and in each frame, draw over their previous locations with the background and then copy the new locations into the previous location variables. |
SonShadowCat
Member #1,548
September 2001
![]() |
I changed my code into this I think instead of deleting and creating bombs, ill just move them... edit: What I really want to know now is how to make the background in my foreground BITMAP transparent so that the background BITMAP shows through |
Thomas Fjellstrom
Member #476
June 2000
![]() |
ouch... when you delete the bomb array, you never reallocate it. so when you try to assign pointers to the places in the bomb array you'll get a memory error. (invalid pointer) Just don't delete the bomb array, and instead: if( check) { for (int a=0; a<10; a++) { delete bomb[a]; bomb[a]=new Bomb(a); } } or even just make a method to reinitialize the bombs: and as for making your bitmap transparent, do you mean translucent? or just seeing through areas that are marked with a special color? -- |
Plucky
Member #1,346
May 2001
![]() |
Quote: What I really want to know now is how to make the background in my foreground BITMAP transparent so that the background BITMAP shows through But you already know how to do this from your code from other threads. In 8 bit color, the "transparent" color is 0 (index 0). A masked_blit() of foreground bitmap to background bitmap would not write over the background wherever a "transparent" color code exist in the foreground bitmap. Perhaps you're not asking the right question? [edit] |
SonShadowCat
Member #1,548
September 2001
![]() |
I know transparent color is 0 but how do I make the white parts of my BITMAP transparent? Ive tried reading through every pixel in the bitmap and checking to see if it was white, if it was I made it 0 Did I do it wrong? |
Thomas Fjellstrom
Member #476
June 2000
![]() |
It depends on the color depth. in 8 bit mode, color 0 is transparent, while makecol(255,0,255) is transparent in the other color depths. I think the best way is to call 'bitmap_mask_color(..)' ie: int mask_color = bitmap_mask_color(bmp); int white = makecol(255,255,255); /* could be different if your color palette has more than one 'white' color... */ for(i=0; i<bmp->h; i++) { for(j=0; j<bmp->w; j++) { if(getpixel(bmp, j, i) == white) putpixel(bmp, j, i, mask_color); } } mind you this is quite slow... but shouldnt be mush of a problem if you only use it on small bitmaps, and then only once in a while. -- |
SonShadowCat
Member #1,548
September 2001
![]() |
Ok, it works, the white part is transparent I should really pay more attention to my code |
Thomas Fjellstrom
Member #476
June 2000
![]() |
what is the code you are currently using for the space key event? -- |
SonShadowCat
Member #1,548
September 2001
![]() |
It was something like this, I kinda changed my code and forgot what it was -.- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
does it crash if 'check' is 0 ? -- |
23yrold3yrold
Member #1,134
March 2001
![]() |
I assume check is supposed to be checked for every bomb, but it'll only check the last with that code. You may want to move the if(check) bit into the for loop, wouldn't you? -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
um. There is a for loop there. so if check is not 0 it will recreate all the bombs. -- |
SonShadowCat
Member #1,548
September 2001
![]() |
I changed my code to the following: It still crashes when I press space |
23yrold3yrold
Member #1,134
March 2001
![]() |
Yes, but if check is 1 for the first nine bombs and 0 for the last, then none of them will be deleted. Arg, ssc beat me ..... -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Is bomb[n]->picture a valid bitmap? [edit:] Chris: I didn't notice he started asigning something to check... [/edit] -- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Especially if you just created one. Try moving the if(check) under the blit just for kicks. -- |
SonShadowCat
Member #1,548
September 2001
![]() |
yes bomb[a]->picture is a valid bitmap, I moved the if statement( not like it was gonna change anything) hmmmm...what could possibly be the problem... Im gonna post my entire code, maybe that'll help
Time to goto sleep, goodnight |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I may be blind, but there isn't one place where you initilize the bombs... for (int a=0; a<10; a++) { bomb[a]=new Bomb(a); } add that right after where you: Bomb* bomb[10];
-- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Try some commenting out. Does it crash if you comment out check = bomb[a]->Collision(foreground)? EDIT: Dang, Tom beat me to it -- |
topaz22
Member #2,049
March 2002
![]() |
it's crashing because you're trying to call a method of an object that hasn't been created, right! there's many ways to fix this, try thomas' idea. |
SonShadowCat
Member #1,548
September 2001
![]() |
...I was pretty sure I had intialized them... gotta pay more attention to my code >< |
Thomas Fjellstrom
Member #476
June 2000
![]() |
no problem. asking other people is usually the way to see mistakes like that. Or waiting a few days (or months) to forget about most of the code, then usually I find stuff like that. -- |
|
1
2
|