Allegro.cc Forums » Programming Questions » What is this exactly? (BITMAP related)

 This thread is locked; no one can reply to it. 1   2
 What is this exactly? (BITMAP related)
 julian_boolean Member #8,201 January 2007 The basic what?
 Rampage Member #3,035 December 2002 I said: arithmetic operators Like +, -, *, / and %. -R
 BAF Member #2,981 December 2002 + is addition. It adds two numbers together. If I have 3 posts and I add 2 posts to it, how many posts do I have?- is subtraction. It takes stuff away. If I have 2,000 posts and I get too trollish, so ML deletes 3, how many posts do I have? is multiplication. If ML deletes 3 posts from 5 users, how many posts has he deleted? / is division. If 430 posts are posted by 10 users, what was the average per user?% is modulus. If I have 2356 posts and I want to have my number of posts be a multiple of 3, what is the closest multiple of 3?
 GullRaDriel Member #3,861 September 2003 God, BAF, you are too good. Julian_Boolean: Are you sure you ever learn C or C++ ? Last time I was cool, but I should not have been that sweet. I told you something helpful. I told you to learn, and learning is always helpful. Now excuse me, but not knowing how to do a division while it is really basic programming... I could not have been more cool with you than telling you should go back to learn. "Code is like shit - it only smells if it is not yours"Allegro Wiki, full of examples and articles !!
 julian_boolean Member #8,201 January 2007 BAF: Thank you very much I already know/heard of the first three. I know division, I just thought / might mean something else. % on the other hand, I had no clue what that meant.GullRaDriel: orly?
 GullRaDriel Member #3,861 September 2003 Oh, really, yes ?I could have told you to RTFM, to stop programming, ... Else I told you to go back learn. So, oh, really, yes.Just launch calc in Windows, and see, the division button, it is a '/' . Astonishing , isn't it ?EDITED "Code is like shit - it only smells if it is not yours"Allegro Wiki, full of examples and articles !!
 Paul Rowan Member #8,612 May 2007 Hi Julian,This bit of code is to help you grab individual sprite frames from a sprite sheet. It's actually in a book called 'Game Programming All In One 2nd Edition by Jonathan S. Harbour' which concentrates on developing games using 'C' and Allegro.An example is of a sprite sheet containing 32 images of a rotating ball, 8 columns wide by 4 rows deep. Each sprite image is 64x64 pixels.What you need to do to make it work is to include this code (say in main()) for ease of showing it is as follows:BITAMP *temp;//load 32-frame tiled sprite imagetemp=load_bitmap("sphere.bmp",NULL); // this is the sprite sheetfor(n=0;n<32;n++) { ballimg[n]=grabframe(temp,64,64,0,0,8,n); }destroy_bitmap(temp);Before main() you need to include:BITMAP *ballimg[32];int n;a quick re-cap of the grabframe function arguments:temp = spritesheet (in this case sphere.bmp)64 = pixel width of frame on sprite sheet64 = pixel height of frame on sprite sheet0 = x start position of 1st frame on sprite sheet0 = y start position of 1st frame on sprite sheet8 = columns of frames (in this case 8 cols x 4 rows)n = frame number (get this from for loop statement)You can have more then 1 set of sprites in a sheet and thats why you can alter the sizes of the width/height of the frames and where in the sprite sheet x,y to start grabbing them from.Hope this helps, but if you need a demo i'll supply a complete code listing and graphics for you to play with
 julian_boolean Member #8,201 January 2007 Yes! Thank you very much!What I wanted to know was how could I do that in C++? (Please don't laugh at me )```// eh? BITMAP* myclass::grabframe(...) { ... } ``` Edit:Would it make it easier to take rows into consideration and use it as a parameter?
 Paul Rowan Member #8,612 May 2007 Sorry, I am only just learning myself how to use Allegro to create games, and I'm using the book mentioned in my previous post which uses C only, and I'm having to learn that too . I have no experience yet of using C++, so I can't help you with your problem
 BAF Member #2,981 December 2002 Uhm... what's not C++ about the original? I don't see many changes you can make to it, unless you put it in a class and make a whole animation system.
 julian_boolean Member #8,201 January 2007 NM! I guess I was just doing something wrong, it compiles now.. But crashes.. BUT I get no errors! So I'm on the right track.
 Paul Rowan Member #8,612 May 2007 If it's compiling OK then ur code is fine. One reason it may be crashing, cos this has happened to me before, is to make sure that the graphics file is being loaded properly into temp - put an error checker on it to see if this loads in correctly first.
julian_boolean
Member #8,201
January 2007

My brother actually has that book, well the third edition. I found a different function inside of it that seems to work better (it doesn't crash and even displays the first frame in the sheet!) But I can't move it around with my arrow keys.

Here's the function:

```void drawframe(BITMAP* source, BITMAP* dest, int x, int y, int width, int height, int startx, int starty, int columns, int frame)
{
int framex = startx + (frame % columns) * width;
int framey = starty + (frame / columns) * height;

masked_blit(source, dest, framex, framey, width, height);
}
```

I fooled around with it and it seems like it should work.

```  drawframe(image, buffer, x_being, y_being, 80, 80, 0, 0, 8, curframe);
```

If I replace curframe with just a number, the correct frame will pop up when I compile it, but I still can't move it.. I think I might know what's wrong but I'm VERY happy this function works.

Edit:

Okay something is really screwed up:

 1 void cplayer::logic() 2 { 3 curframe = 10; 4 } 5 6 void cplayer::draw(BITMAP* buffer) 7 { 8 drawframe(image, buffer, x_player, y_player, 80, 80, 8, curframe); 9 } 10 11 ... 12 13 // elsewhere 14 15 cplayer* player; 16 17 player->logic; // inside the game loop

It's still showing frame 0 on my sprite sheet for some reason.

 GullRaDriel Member #3,861 September 2003 Hum...There is NOTHING magic in programming. If you need it to step one frame, you must tell it to do so.The line drawframe(image, buffer, x_being, y_being, 80, 80, 0, 0, 8, curframe); will always draw the same frame until you make some change.I see a curframe = 10, I do not see a curframe ++ or something else.I think that you should really spend some times understanding how this (simple) function works. "Code is like shit - it only smells if it is not yours"Allegro Wiki, full of examples and articles !!
 julian_boolean Member #8,201 January 2007 Quote: I do not see a curframe ++ or something else. Your point? I already found the problem and it a simple mistake (had nothing to do with the function.) After fixing it setting curframe to 10 works, obviously.
 LennyLen Member #5,313 December 2004 Quote: After fixing it setting curframe to 10 works, obviously. If you've fixed the problem yourself, you should make an addendum to your post, so that others don't keep trying to solve the problem for you.Also, why does your function take x and y parameters if they're not being used?
 GullRaDriel Member #3,861 September 2003 julian_boolean said: It's still showing frame 0 on my sprite sheet for some reason. ...Your point? I already found the problem and it a simple mistake (had nothing to do with the function.) After fixing it setting curframe to 10 works, obviously. First: You never wrote that your problem was solved.Second: If you are initializing curframe to 10 without knowing why, you do not understand the function correctlyThird: If something need to change for you seeing the sprite moving, that is curframe.Ending:I never said there was a problem with the draw_frame function, I say there is one with the way you use it.EDIT: beaten a few by LennyLen "Code is like shit - it only smells if it is not yours"Allegro Wiki, full of examples and articles !!
 julian_boolean Member #8,201 January 2007 They are being used, just not in the code I showed.I set curframe to 10 so I could test to see if the proper frame would show up on the screen, using the x and y coordinates given somewhere else in the program.
 1   2  Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads