Hello guys, i'm facing a problem with my program:
I've only write a code for make a circle walk 10 pixels on the screem 60 times per second, but the circle sometimes "jumps", like if it have walked 50 pixels or more instead of 10, I'm going to post my main loop, hope you can help me finding where is the problem
Remove the ! before al_is_event_queue_empty(). You want to call al_wait_for_event when the queue is empty and wait until there is an event. The way you have it you would only wait for an event if there already is one, so never... which means your loop just runs through millions of times heating up a CPU core and making everything unstable and jumpy.
Hi Elias, thanks for your reply, I tried to change the main loop but unfortunely my drawings are still jumpy.
I tried a lot of new combinations, but none of them seems to solve the problem
I also tried a logic with two timers, one for the logic and other for drawing, but it have not worked too.
I always use this as my main loop, the only thing that I notice is that your code does not have the "ALLEGRO_EVENT event;" before "al_wait_for_event(eventQueue, &event);"
trictonicmp's loop looks right to me. The key points are:
call al_wait_for_event when there's nothing else to do
only redraw when there was a timer event
only redraw when there are no events left in the queue
Good thread. I'm going to try upgrading Ramen's loop using the advice in here.
Fixing the formatting and making it more condensed :
This is pretty much the standard loop, and has been on the wiki for a while. It's just your basic event loop.
Guys, thanks for all the answers, but i'm beginning to get worried about it.. I have removed all the miscellaneous code and I'm going to put here what i'm compiling, it is only three classes, maybe this way it will be easier to find my problem, if there is one:
it's really strange, it only prints a red ball moving from one side to another, but it still give some 'jumps' at every two seconds approximately
edit: if you guys want, you can run this program only with this code below, i don't discard the possibility of the problem be my installation, and not in my code, who knows..
If you're going to provide code, provide something that compiles please.
Here's your code fixed up and compiling :
The resulting exe works fine. The red ball goes back and forth smoothly. There was one glitch on the first run, where it skipped a little, but I assume that was a vsync timing issue.
I'm sorry Edgar, I have removed a lot of classes, I did not see the remaining variables.
So, I don't think that the problem is my computer, maybe I have messed up when installing codeblocks and allegro, but I'm less worried now that it worked fine for you.
do you guys know a recognized tutorial for installation of allegro with any IDE? for windows or linux?
I wouldn't consider it solved yet.
The code listed works fine when graphics takes less than 1.0/FPS, but when it takes longer than that, you will have frame skipping. The solution is to discard all timer events after the first in each iteration.
This will skip all extra timer events in case they pile up, and it will slow down gracefully.
Edgar, I've tried to put this new variable to avoid updating twice before drawing, but my problem persists, unfortunnely..
I have also tried to leave only the al_flip_display() on my Draw function:
but it did not help. Damn, I was pretty sure that the ticks variable would solve the issue hahahaha
edit: I've checked my screen refresh rate and it's on 60Hz
do you guys know a recognized tutorial for installation of allegro with any IDE? for windows or linux?
MSVS is pretty easy. All you do is use Nugat to install Allegro. MinGW and CodeBlocks is not super hard either, but takes some work. Linux can be as easy as 'sudo apt-get install liballegro5-dev' if you're on Ubuntu.
but it did not help. Damn, I was pretty sure that the ticks variable would solve the issue hahahaha
edit: I've checked my screen refresh rate and it's on 60Hz
It literally has to move 10 pixels at a time, there's something else going on.
Did you compile and run the code I gave back to you?
Guys, I've found the problem, it was not the code, but an old VGA monitor that I was using with my notebook, I don't know exactly why, but when I disconnect him the circle moves smoothly on the screen
Anyway, thanks Edgar and thanks for all who have replied!!