![]() |
|
Help With C++ Objects |
Genius314
Member #6,626
November 2005
|
I recently started using C++ OO, and I'm a complete n00b. Oh, and also, is there a way to get one tile or sprite from a sprite sheet or tileset? Because right now, i have the sprites in spritesheets, and I'm not sure how to just get a small section of it. Is there some sort of cropping code? Thanks, |
miran
Member #2,407
June 2002
|
Quote: I can't quite figure out where the code goes for loading and drawing sprites. Anywhere you want. Quote: Everywhere I put it, Define everywhere. Quote: it doesn't work Define doesn't work. Quote: Does it go inside the class, or in with the initializations? Inside the what? Quote: Oh, and also, is there a way to get one tile or sprite from a sprite sheet or tileset? Because right now, i have the sprites in spritesheets, and I'm not sure how to just get a small section of it. Is there some sort of cropping code? BITMAP *create_sub_bitmap(BITMAP *parent, int x, y, width, height) -- |
kentl
Member #2,905
November 2002
|
Actually Genius314 you should read a C++ tutorial and complete its assignments before you start making games. I think you will find that it's well invested time, and you've got to learn this stuff anyway if you want to create games using C++. |
Jonny Cook
Member #4,055
November 2003
|
Something like that. The face of a child can say it all, especially the mouth part of the face. |
Elverion
Member #6,239
September 2005
![]() |
Normally, you don't want to load or toy with bitmaps within an object. It's a bad idea. You should maybe load a datafile full of all your sprites at the beginning of your program as a global datafile, then in your objects constructor do something like MyObject::MyObject() { // MyObject's constructor mysprite = (BITMAP *)graphics_dat[MYSPRITE].dat; } Then, make your object have a draw function that draws onto the specified bitmap. void MyObject::draw(BITMAP *dest) { masked_blit(mysprite, dest, 0, 0, x, y, mysprite->w, mysprite->h); } Of course, you could get a little bit more fancy and make an array of BITMAP * for use in multiple frames using create_sub_bitmap. I'll leave that up to you to toy around with. Remember to unload your datafile at the end of the program. -- |
piccolo
Member #3,163
January 2003
![]() |
i think you should check out my game it will be a great help to you http://www.allegro.cc/depot/Thegame/ wow |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: I recently started using C++ OO, and I'm a complete n00b. Good to hear you are aware of that. Quote: I can't quite figure out where the code goes for loading and drawing sprites. Everywhere I put it, it doesn't work. That's probably because you lack essential coding skills. Quote: Does it go inside the class, or in with the initializations? The class? There can be more than one class, you know. And if by "initialization", you mean "constructor", I'd say rather not. But the question in itself is void, unless you tell us what else it needs to do. Quote: Oh, and also, is there a way to get one tile or sprite from a sprite sheet or tileset? Because right now, i have the sprites in spritesheets, and I'm not sure how to just get a small section of it. Is there some sort of cropping code? blit() and create_sub_bitmap() can help a lot, although they are not fully-fledged miracle tools that do all of your dirty work for you. They can't be, because they don't know how your sprite sheet is laid out. I'm afraid you need to do this yourself. Anyway, considering your very first sentence, I'd say - --- |
Genius314
Member #6,626
November 2005
|
Ok, now i feel really stupid. |
LennyLen
Member #5,313
December 2004
![]() |
Quote: Apparently the only problem is that i can't name classes as "player." Any other name works. try using namespaces.
|
Tobias Dammers
Member #2,604
August 2002
![]() |
Or else, use one of the common style conventions that prevent things like this to happen. The most common one would be this: A more allegro-ish way would be to use UPPER_CASE_WITH_UNDERSCORES for all type names, macros and constants, and lower_case_with_underscores() for variables and function names. It's not important which convention you use, as long as you choose one and stick to it. It helps to be able to see what kind of indentifier you're looking at when you see it. --- |
Ceagon Xylas
Member #5,495
February 2005
![]() |
Quote: i think you should check out my game it will be a great help to you Always. Quote: Apparently the only problem is that i can't name classes as "player." Any other name works.
That's weird, I name a class 'player' in just about every single one of my games. |
|