Solved

OnTimer() - clockspeed

Posted on 1998-09-22
5
371 Views
Last Modified: 2008-02-26
I have written a a game in VC++5.0, similar to "nibbles", where the user controls a worm that runs across the screen. To display the bitmaps I used the OnTimer() command.
 
Although the game runs fine on my computer, I have tried it on other computers and the worm moves at different speeds.  My computer is running win95 and a slower computer running winNT makes the worm move incredibly too fast to play it.

Can anyone please show me how to set the clockspeed temporarily durring the program, or write a function that will make the game run at the same speed on all systems?
0
Comment
Question by:SileNcer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:SileNcer
ID: 1173435
Edited text of question
0
 

Author Comment

by:SileNcer
ID: 1173436
Edited text of question
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 20 total points
ID: 1173437
When you do SetTimer you specify the interval between timer messages (smaller interval makes the game run faster).

Paradoxically I think you have set the timer value too _high_.

WM_TIMER messages may not always get thru (they are not guaranteed).  On the slow computer some are probably being dropped as the screen is still updating or whatever, on the faster computer, more (or all), get thru, hence the faster game.

Change the 2nd (MFC SetTimer) or 3rd parameter (Win API SetTimer) function.  Increase the value.  It's in milliseconds (1000 = 1 second).  Also don't go below 1000/18.
0
 

Author Comment

by:SileNcer
ID: 1173438
Thanks, I had the timer set to 0, I can change it all the way to 40 and it runs the same, which was the difference between the two computers.
I guess if I want the game to go faster, different skill levels, I can set up another timer.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173439
The _slowest_ computers have 18.2 ticks per second hence the 1000/18,
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question