User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Oct 2005
Posts: 20
Reputation: Savage221 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Savage221 Savage221 is offline Offline
Newbie Poster

C++ Graphics (graphics.h)

  #1  
Dec 5th, 2005
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 596
Reputation: SpS is on a distinguished road 
Rep Power: 5
Solved Threads: 31
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: C++ Graphics (graphics.h)

  #2  
Dec 5th, 2005
compare the current coordinates of text or picture with screen coordinate...and if it's larger than that...then take suitable action to correct it
Reply With Quote  
Join Date: Dec 2004
Location: Hiawassee, Georgia
Posts: 129
Reputation: Geek-Master is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
Geek-Master's Avatar
Geek-Master Geek-Master is offline Offline
Junior Poster

Re: C++ Graphics (graphics.h)

  #3  
Dec 9th, 2005
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC