Hello.
My game met a problem.
Very simple function:
Use 4 keyboard buttons to move the unit.
But, very unlucky ,It doesn't work properly.
The situation is:
Press the ( any button, this is an example ) up button and the unit will go up.
1. the unit will not move.
2. do not move, wait a little time, move like a rocket(It's like having superpowers).
In fact, the speed of the unit is very slow.
What happened?
========================================
Add:
It looks like a game caton. Just like some games, network delay, instant movement.
I guess it's my quadtree that consumes too much time?(Map data)
========================================
Add:
The code is below.
Show your event handling code and your movement code.
It only does what you tell it to. :/
You need to process all events as soon as they occur. This means you can't be blocking in 'quad_tree()' while you're processing events.
Try restructuring your code so that QuadTree() is called less often. Process every event as soon as you get it. Try something like this :
I wish Allegro were a bit more helpful with the main loop (for example, providing a higher level function for the common case). It's difficult to get right and, last time I looked, the Allegro example games all do it a bit differently.
Edgar - in your example I think it will spin around the loop even if there are no events. Not a big deal but it might impact power use adversely (and have the fans running etc.) Although, in this case, if quad_tree is doing a lot of work the CPU will be 100% anyway.
Peter - yeah, I figured he would want to use 100% CPU in this case, because his QuadTree function would be taking a lot of time. I thought he wouldn't want to waste time waiting for an event if he needed to be processing quad_tree.
It can easily be altered to wait for an event.
do { ALLEGRO_EVENT ev; al_wait_for_event(q , &ev); } while (!al_is_event_queue_empty(q));