#### Archived

This topic is now archived and is closed to further replies.

# Getting back into programming...

This topic is 6042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

After hitting a wall in my studies, I got frustrated and gave up programming. But, as many others have found, you cannot stay away. This is the curse of programming. I am ready to pick up where I left off, and I am trying to get a head start on getting over this wall, so hopefully someone can help a brother out. My issue is, I am having a hard time finding out how using graphics in programming works. And Im not talking about 3D, or anything advanced for that matter. I just want to be able to work a graphic in with some simple logic, maybe mke it appear and disappear, maybe make it move around, or alternate between images. I have just about every programming book known to man, including a couple books on DirectX, C/C++ books, and WinAPI books. Im sure I will figure this out if I keep searching, but I have found a lot of help in these forums and I am hoping I can find it here again. Noods

##### Share on other sites
Uh... what was your question again?

##### Share on other sites
I'm assuming your using C++ (cuz of the books)

Ok, I'm also going to assume you know a bit of DirectDraw at least.

Ok, now, the graphic you want to display and move around and make it disappear and all that jazz is called a sprite.

So, we'll start by making a Sprite class... we'll call it CSprite

Ok, so we know that we have to have a position for it, and if it's going to move we'll probably want a velocity, and since it's going to disappear and reappear we'll need a visibility flag.

With me so far? Good...

So, now our CSprite class looks like this (pretty much)

    class CSprite{   int X;    // X position (left side of the graphic)   int Y;    // Y position (top side of the graphic)   int dX;   // X velocity (amount to move by for each frame)   int dY;   // Y velocity   bool vis; // Visibility flag (true = visible)}

So, now we have a skeleton sprite class...
Since this is a class, all the members default to private... this means we'll need a public interface to be able to modify the members of the class.

Specifically (and you can do this with overloading or not) we are going to need Setters and Getters (That's my way of saying things like SetXvel() and GetVis() )

I'll leave it up to you to add those since they are really simple and you could probably just inline all of them...

So, how do we check if we should draw the graphic? That's the easy part with using our sprite class... All we do is go through a loop (looping through the sprites if there's more than one (somehow storing them, possibly a link list)) and just check if it is visible:

if (soandsosprite.GetVis() == true)
{
blit it;
}

Now, for frames of a sprite...

We'll need members that tell us 1) How many frames in the animation, 2) Which frame we are on, and 3) How fast the frames should change (probably in milliseconds)

I'm gonna leave it for you to figure out that part because 1) I think you can do it without too much work and 2) I've gotta go get some rest (big long hike earlier today)

And that's it, easy as pie, or cake, or something good like that...

Have fun...

I'm learning, just like the best of us...

[edited by - Soulkeeper on June 3, 2002 1:49:52 AM]

##### Share on other sites
Just a suggestion, but it may be easier for you to learn by using something like

Allegro
http://www.talula.demon.co.uk/allegro/

or Libcon
http://photoneffect.com/default.html

Allegro's harder to set up but it's cross platform and VERY easy to use, done in C. I learned alot with this... The documentation is -amazingly- simple and complete.

Libcon's harder to use and get used to but it's done in very object oriented C++. Done by a very helpful guy named Photon. It's also strictly for MSVC++ 6.0, Windoze only.

They're basically "wrapper" libraries that simplify the interface of DirectX (with Allegro, only when it's being used on windows, of course). If the DirectX interface is giving you headaches, you can try one of these two or a different library... at the very least it'll help you get something cool going in a short period of time (after they are installed ), and that'll help you to stick with it!

To anon: Wiseass... lol

[edited by - Tebriel on June 3, 2002 3:04:02 AM]

##### Share on other sites
And the God said:
"Thou shalt not use Allegro !"

And God gave men SDL...
Donuts...

Really, it''s better than Allegro.

##### Share on other sites
Along the lines of Tebriel''s post, some more libraries are: SDL and ClanLib.

##### Share on other sites
Well, I haven''t used Allegro in years so you may be right.

But still, don''t crap on my old-school library!

6 Phases of a Project
1) Enthusiasm

2) Disillusionment

3) Panic

4) A Search for the Guilty

5) The Punishment of the Innocent

6) Praise and Honor for the Non-Participants

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013758
×