hello!
i would like to make a moving sprite...
i want a sprite to move 100 units.. but he moves way toooo fast... i would like to make a slow movement like a moving platform
and how to make something like that:
sprite move to x 500, y 500 then wait for 5 secods and move to x 200 y 200...??
Put your game in a continuous loop.
Break up all your logic into "frames" (like in a movie) rather than trying to do it all at once.
Use a timer to regulate the number of logic frames performed each second. A typical value is 60 frames per second.
Reviewing the example programs that come with Allegro might provide an insight into how to accomplish this.
well i have no idea how to slow down my sprite movements... my sprite moves randomly but it is tooo fast i would like to move every one or two seconds
and timer class.. i have no idea what to do about this:
In your original post, you had a loop that, for as long as the key was held down, the X coordinate was updated. However, you did not have any sort of timing delay that said, "if the key is STILL down, wait for 0.1 seconds before updating the X coordinate again." So it's just going as fast as possible.
(EDIT: fixed)
An outer loop should be handling your timing. Your inner loop should detect whether the mouse key is still being held down.
If so, evaluate whether your character has moved all 100 pixels. If not, move the X coordinate once (but not more; don't have it inside a while loop). If you have already moved all 100 pixels, either wait until the user releases the key, or (if your logic is setup this way), wait a predetermined amount, then reset the "character has moved" counter to 0, and repeat the "move 100 pixels" logic.
For your next post, you appear to only be storing your current position, but not a "destination" position. I would suggest having both.
If your ship is to move to a specific location, your "destination_x - current_x" will tell you both the direction your ship needs to move, as well as whether you need to keep moving, or (if the numbers are equal) whether to just sit where you're at.
If the user presses a key and releases it very quickly, do you want them to stop moving, or continue toward their destination? If you want them to stop, you can simply set the "destination_x" to wherever the ship is currently; your logic will continue to try to move the ship to its destination, but since you're now "there", you don't have to move anymore.
well looks like i will have to use some math stuff to get destination movements working
i have got one question.. how do i slow down my application? i would like to start the void Ship::Think( void ) function every 0.5 second.. so my sprite doesnt blink anymore... i want him to teleport every 0.5 second...
it is possible to slow down my keyboard states in allegro? for example when i push F1 button just once for a little... the console looks like that:
F1 - button
F1 - button
F1 - button
F1 - button
F1 - button
i dont know why it counted 5 clicks
or should i call al_set_timer_speed(myTimer, 0.5)??
Are you drawing directly to the screen, or to a buffer? With Allegro 5, you usually have multiple buffers: one is being currently displayed to the screen, and the other(s) are being drawn to in the background, to prevent flickering/tearing that occurs when you try to draw to the screen directly.
Your logic for the key down problem is probably due to the fact that you're hitting the logic for "is the key down?" several times very quickly, but you don't have something that says "the key WAS down the last time I polled the keyboard, and it's STILL down now, so ignore the key for now." When you finally release the key, your "key_was_down" will be set to false, and the next time you enter that function, you'll have "the key WASN'T down the last time I polled the keyboard, but it's down NOW, so run this logic loop."
Essentially:
This may need some adjusting. If you want the ship to move while the key is still being held down, but pause for some "key repeat delay" amount of time, you can change the line from
to
i have got one question.. how do i slow down my application?
Use a timer to regulate the number of logic frames performed each second. A typical value is 60 frames per second.