![]() |
|
blitting sprites |
Money
Member #6,730
December 2005
![]() |
hey, i have a .bmp, its a..well a bunch of sprites, i got a suggestion to blit the sprite frame onto the screen, but it still didn't work, i only need one static image of a sprite, not all of its movements. here is my source.
download attachment, its a screenshot of the output. |
Jonny Cook
Member #4,055
November 2003
|
Check the documentation for blit. You can use it to draw only parts of a bitmap. [edit] The face of a child can say it all, especially the mouth part of the face. |
Money
Member #6,730
December 2005
![]() |
well, i have while ( !key[KEY_ESC] ) release_screen(); } and it still didn't work. when you said palette did you mean like Palette palette; |
Onewing
Member #6,152
August 2005
![]() |
Does your sprite have a white background? Typically, you'll want to use the masking color (rgb(255,0,255)) as the background instead. This way, when you blit the image, anything with that pinkish color will not overwrite what is behind the image. Note, you will have to use masked_blit instead of just plain ole blit. For just picking out a certain portion of the image, yes, check the documentation of blit. ------------ |
Alex Hanson-White
Member #6,657
December 2005
![]() |
edit |
Money
Member #6,730
December 2005
![]() |
no that still didn't work while ( !key[KEY_ESC] ) release_screen(); } download attachment..it is a screenshot |
Miles Lombardi
Member #5,876
May 2005
|
Quote: You can just pass NULL as the pallet when you are using 15 or higher color depth.
As he said just use NULL, it'll stop the complications of it using a palette. |
Money
Member #6,730
December 2005
![]() |
//main game loop while ( !key[KEY_ESC] ) { acquire_screen(); release_screen(); rest(30); } ok, so i don't use blit, then what do i do? i just want static image, so then i can animate it from input(keyboard). |
Miles Lombardi
Member #5,876
May 2005
|
I don't use acquire_screen() and released_screen() used to annoy me because they get very spread out over the entire loop and eventually i got rid of them and i can't remember why now, but i think acquire_screen is only needed when your using primitives, rather than bitmaps. But I don't understand why this wouldn't work (standard blitting code): You only need to worry about masked_blit when you want transparency (say for your moving character). Just put that in between acquire and release screen and i don't see why it shouldn't work :S. And oh btw, I have to ask why these dimensions: masked_blit(screen , screen, 0, 0, 90, 90, 70,70); It seems a weird area of the screen to copy. |
Onewing
Member #6,152
August 2005
![]() |
Do this: bmp = load_bitmap( "sprite.bmp", NULL); [EDIT] Quote: I don't use acquire_screen() and released_screen() Nor do I. ------------ |
Money
Member #6,730
December 2005
![]() |
hmm, still didn't work, all of the sprites still showed up.
|
Jonny Cook
Member #4,055
November 2003
|
That would blit a 32x32 section of sprite.bmp. The face of a child can say it all, especially the mouth part of the face. |
Richard Phipps
Member #1,632
November 2001
![]() |
Money: I have a selection of game creation articles I wrote some time ago. They deal with creating a gauntlet style game using simple C and allegro commands. Maybe that will help you understand how things work? |
Money
Member #6,730
December 2005
![]() |
ok, it worked, jonny, thanks now only the top head was shown, so i think i need to put the width and height greater, um, you said to get rid of the white background too use masked_blit on the sprite? |
Jonny Cook
Member #4,055
November 2003
|
Not sure why that would happen... but I haven't tested it so it could be something wrong. I was just giving an example of how to blit a portion of a bitmap to the screen. Oh, and I forgot to destroy the image. [edit] The face of a child can say it all, especially the mouth part of the face. |
Money
Member #6,730
December 2005
![]() |
alright, well i guess i need to do 255, 255, 255 because the sprites background is white. is there an exact way to get the coordinates of the first frame, rather than to keep testing coordinates to see if the frame is there? last thing, if i wanted to animate it, i just load another frame and just blit it and delete the last frame correct? sorry for all of thesse questions, but this is the stuff i can't find in the api, documents , or examples, their using c, and its kinda difficult for me. in the example files its different. edit: richard, thanks a lot! |
Jonny Cook
Member #4,055
November 2003
|
Quote: alright, well i guess i need to do 255, 255, 255 because the sprites background is white. I'm afraid you'll have to change the background to pink. Allegro has the it hardcoded in. Quote: is there an exact way to get the coordinates of the first frame, rather than to keep testing coordinates to see if the frame is there? If you have all the frames the same size, you can do something like this: int src_x = image_w * frame; Assuming you have them all in one line, src_y should be 0. Quote: last thing, if i wanted to animate it, i just load another frame and just blit it and delete the last frame correct? You shouldn't do any loading or deleting in the main loop. Load the big image at the beggining, and then do something like this: int src_x = sprite_w * frame; int src_y = 0; blit(big, buffer, src_x, src_y, sprite_x, sprite_y, sprite_w, sprite_h);
That would work only if all your frames are the same size. The face of a child can say it all, especially the mouth part of the face. |
Onewing
Member #6,152
August 2005
![]() |
Quote: alright, well i guess i need to do 255, 255, 255 because the sprites background is white. I don't think you can do that. I would just open up the picture itself and fill the background with pink (255,0,255). Quote: is there an exact way to get the coordinates of the first frame, rather than to keep testing coordinates to see if the frame is there? Again, open up the picture and set it up to where the images can be found at a given length in an x,y direction. Quote: last thing, if i wanted to animate it, i just load another frame and just blit it and delete the last frame correct? Shouldn't have to delete it, if you have your design right. ------------ |
Money
Member #6,730
December 2005
![]() |
hmm i opened the sprite up in ms paint, and changed that backgound to pink(255, 0, 255), when i recompiled and ran the .exe , the pink background showed up, i changed it to black , it was perfect, but thats not very smart when i load like other bitmaps in ,like buildings and stuff, because you'll e able to tell there is a black background stuck to the sprite i used while( !key[KEY_ESC] ) { acquire_screen(); masked_blit(big, screen, 32, 0, 640/2, 480/2, 40, 90); release_screen(); } what could be wrong, im doing everything right. [edit] |
Onewing
Member #6,152
August 2005
![]() |
Quote: and changed that backgound to pink(255, 0, 255) Are you sure? If you are off, even by 1 (e.g. 254,0,255), then the pink will show up. Quote: when i recompiled and ran the .exe
No need to recompile, you are changing the bitmap, not the code. Are you blitting the sprite to 'big' somewhere or is 'big' the loaded picture? ------------ |
Money
Member #6,730
December 2005
![]() |
nope, i have tried like 3 different pinks, but it still shows up, here is the code:
i don't possibly see what i could be doing wrong :| |
Evert
Member #794
November 2000
![]() |
Attach the picture. |
Richard Phipps
Member #1,632
November 2001
![]() |
Can you attach the sprite to a post so we can have a look? |
Onewing
Member #6,152
August 2005
![]() |
Quote: nope, i have tried like 3 different pinks, but it still shows up, here is the code: If you are trying different pinks, then that's not going to work. Do this: 1) Open PAINT ------------ |
Money
Member #6,730
December 2005
![]() |
[edit] alright, i got it to work, turns out it was ms paint messing up, i downloaded neopaint and edited the palette to 255, 0, 255, and used that as the background, so i guess i stick with neopaint thanks all of you for helping me out, i have not yet seen a post this long for one problem, sorry about the credits i had did that earlier, on like the 1st page, but thank you all so much, you've been such a big help Credit goes to all who replied on this subject...except to craig, no credit goes to craig whatsoever |
|
|