•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,930 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,426 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2234 | Replies: 2
![]() |
•
•
Join Date: Oct 2005
Posts: 20
Reputation:
Rep Power: 4
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.
•
•
Join Date: Dec 2004
Location: Hiawassee, Georgia
Posts: 129
Reputation:
Rep Power: 4
Solved Threads: 1
•
•
•
•
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.
Here are some steps I would take:
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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..


Linear Mode