| | |
C++ Graphics (graphics.h)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2005
Posts: 20
Reputation:
Solved Threads: 0
I just had a pretty basic question regarding graphics in C++ using the header graphics.h. How would you take a shape or just regular text and randomly move it around the screen like you would see in a screen saver? Just looping it to randomly display it in different areas is simple enough, but I'm trying to go for that constant moving effect. Any help would be greatly apprechiated.
•
•
•
•
Originally Posted by Savage221
I just had a pretty basic question regarding graphics in C++ using the header graphics.h. How would you take a shape or just regular text and randomly move it around the screen like you would see in a screen saver? Just looping it to randomly display it in different areas is simple enough, but I'm trying to go for that constant moving effect. Any help would be greatly apprechiated.
1. Setup Coordinate Parameters and Direction Flags
If you are in full screen mode then all you will need to do is obtain the screen size i.e.(800x600).
If you are dealing with a rectangle box, then you will need to set up 4 variables that will determine when the object needs to "bounce off" and change direction.
You will also need to set up 2 flags that will determine the movement along the x and y axis.
Not only will you have to take in consideration of your "borders", but your objects size. This can be done by subtracting the size of your object, which is another rectangle too, from your parameters. This will make sure your object doesn't slide off the screen, since the object's coords will come from the top-left point.
2. Test your object with these parameters
You will need to set up some conditions to test if your object didn't "hit" the parameter you set up.
When the object hits a parameter then you will need to turn off or turn on one of the direction flags.
Depending on what direction you are in you will need to decrement or increment the value of your object's coordiantes.
Moving the object by one pixel will give it the smooth motion effect you want.
3. Draw your object in its new location
You can adjust the speed of the object by how often the trigger goes off on the Draw function, which will probably be in milliseconds.
Sorry I can't give any example code for this. I've only worked with graphics using VB.NET on a version of PONG. So I think the theory can get you rolling further.
If in doubt, reach into the trash can and remove the user guide.
![]() |
Similar Threads
- Creating graphics (Visual Basic 4 / 5 / 6)
- C++ Graphics!! (C++)
- DOS Graphics (Game Development)
- Amazing Website Designs - How do they do this? (Site Layout and Usability)
- graphics / compiler problem (Java)
- graphics - where to start? (C++)
Other Threads in the C++ Forum
- Previous Thread: Creating Functions to print to screen.
- Next Thread: How to use wifstream to read a unicode file..
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





