Making a texture manager
Hello David,
Sprite programming is really fun, because once you get it out of the way you'll be producing games like crazy, because sprites are the foundation of animation in game programming, and games are just animation with rules.
Anyway, I like the idea that your trying to do everything in modules, but their only useful if their properly organized, if you're wrapping every method in a module, it becomes redundent, and adds coding overhead with no benefit. The whole point of modules is to organize your code.
I would converge your spriteframe, and sprite class all together into a class called cSprite, and only keep SpriteBase separated. Have cSprite take care of what frame its on, and what animation to use, and where to find this animation, and have a SpriteBase object in Sprite. Your Object class, commonly known as an Entity class would then have have a pointer to cSprite. So to answer your question the user would then create a Entity object like so</pL
{ Entity Monster_Ogre(x, y); Monster.cSprite = new cSprite("Ogre", x, y);}// here is a pseudo code implementation of cSprite()cSprite::cSprite(char *AnimationSet, int x, int y){ if ( strcmp(AnimationSet, "Mermaid") == 1) { GraphixManager::LoadSpriteSheet("MermaidSS.bmp"); cSpriteBase::LoadAnimationInfo("Mermaid.ani"); // SpriteBase then takes in the animation details } if ( strcmp(AnimationSet, "Ogre") == 1) { GraphixManager::LoadSpriteSheet("OgreSS.bmp"); cSpriteBase::LoadAnimationInfo("Ogre.ani", animation_info); // SpiteBase then takes in the animation details. } // assign member data position_x = x; position_y = y; animation_frame = 0; // rest of implementation}
During your game logic, if the Monster_Ogre was moving, you would tell its cSprite to use its animation method with the "Ogre_Walking" animation, by calling its Animation Method cSprite.Animation("Walking"), if the monster was fighting you would call cSprite.Animation("Fighting"), if the monster takes damage you would call cSprite.Animation("Damage"). Because you already loaded the sprite sheet into memory when you created your entity, loading animation is as simple as telling your image pointers where to point to.
void cSprite::Animation(char *NameOfAnimation){ if (IsAnimationDifferent() == true) // see if were doing a different animation { SpriteBase::GetAnimationDetails(NameOfAnimation); Frame = 0; // reset which frame we're on MaxFrames = SpriteBase::MaxFrames; // redudent, just to illustrate how cSPrite and SpriteBase work } AnimateFrame(NameOfAnimation, frame, x, y); frame++; if (frame == SpriteBase::MaxFrames) { frame = 0; // loop the animation } };// pseudo implemantation of AnimateFramevoid cSprite::AnimateFrame(char *NameOfAnimation, int frame, int x, int y){ IMAGE *ptr = (IMAGE)SpriteBase.GetImage(NameofAnimation, 5); Render::TransparentBlit(ptr, x, y); // this can a global object that all entities see, or you can have a pointer to it in your sprite class, the skys the limit.// just keep it organized}
That's one way to do it, you don't need anything else, its that simple, your Entity object will take care of its position and whats happening to it, your Sprite only has to worry about what it's animating, your renderer takes care of actually rasterizing the images, and you only have to take care of your game logic.
Quote:
and games are just animation with rules.
Actually games are just rules. How you choose to present those rules to the player(s) is up to you, and by providing well engineered, modular code you can more easily mix/match/fix/upgrade the presentation of the game. Not so infrequently you won't even present animations, images or anything to the player with multiplayer gaming as prevalent as it is.
Oh, and strcmp returns 0 on a match, not 1.
Quote:Original post by ordered_disorderHello David,
Sprite programming is really fun, because once you get it out of the way you'll be producing games like crazy, because sprites are the foundation of animation in game programming, and games are just animation with rules.
Anyway, I like the idea that your trying to do everything in modules, but their only useful if their properly organized, if you're wrapping every method in a module, it becomes redundent, and adds coding overhead with no benefit. The whole point of modules is to organize your code.
I would converge your spriteframe, and sprite class all together into a class called cSprite, and only keep SpriteBase separated. Have cSprite take care of what frame its on, and what animation to use, and where to find this animation, and have a SpriteBase object in Sprite. Your Object class, commonly known as an Entity class would then have have a pointer to cSprite. So to answer your question the user would then create a Entity object like so</pL
*** Source Snippet Removed ***
During your game logic, if the Monster_Ogre was moving, you would tell its cSprite to use its animation method with the "Ogre_Walking" animation, by calling its Animation Method cSprite.Animation("Walking"), if the monster was fighting you would call cSprite.Animation("Fighting"), if the monster takes damage you would call cSprite.Animation("Damage"). Because you already loaded the sprite sheet into memory when you created your entity, loading animation is as simple as telling your image pointers where to point to.
*** Source Snippet Removed ***
That's one way to do it, you don't need anything else, its that simple, your Entity object will take care of its position and whats happening to it, your Sprite only has to worry about what it's animating, your renderer takes care of actually rasterizing the images, and you only have to take care of your game logic.
Cool that sounds good. So each sprite file stores all the possible animations for that sprite and each of the animations has a name.
So I would load a sprite text file up, setup the cSpriteBase with its values + an array of all the possible animations, then add a cSprite using that cSpriteBase and then add an object using that cSprite.
Say when I wanted to add an object that was an ogre though, where would I start? somthing like game_engine.add_object("ogre.txt") ?
I pretty much understand how to do it now, thanks for the replys.
Quote:
Say when I wanted to add an object that was an ogre though, where would I start? somthing like game_engine.add_object("ogre.txt") ?
Yes, that's it, the implementation is up to you. Generally it's very automatous, where you engine is adding and deleting objects based on the type of game your creating, and the parts that are being played.
Quote:Original post by kzar
Is there a way to loop through every single entry in a std::map ?
for_each(...), or the general for(iterator=map.begin();iterator!=map.end();++iterator){