Animations in Allegro

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 5159 Views - Last Post: 31 January 2009 - 01:43 PM Rate Topic: -----

#1 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Animations in Allegro

Posted 24 January 2009 - 07:48 PM

I have a question, how do you make the computer put a image on the screen, wait a second and then replace the image with another image. This code could be used to make a loading animation for my game. I'm using the library Allegro by the way.
#include <allegro.h>
BITMAP *Load_bar;
int main(){ 
	allegro_init();
	install_keyboard();
	set_color_depth(16);
	set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
	Load_bar = load_bitmap( "Line.bmp", NULL);
	acquire_screen();
	draw_sprite( screen, Load_bar, 250, 7);
	release_screen();
	readkey();
	return 0;
}   
END_OF_MAIN();


Attached File  Line.bmp (214bytes)
Number of downloads: 131

Is This A Good Question/Topic? 0
  • +

Replies To: Animations in Allegro

#2 matthew180  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 07-January 09

Re: Animations in Allegro

Posted 24 January 2009 - 08:35 PM

Usually you want your progress indicators to reflect that something is "really" still happening, and to also be as linear as possible (ever been frustrated by a progress bar that sits at 1% for 5 minutes, then jumps to 99%, then done?)

Typically for file loading your progress could be done in a couple of ways depending on how you are actually loading the data. If you are directly controlling the loading of the file, i.e. using read() or fread() into data structs or image buffers, then I would suggest dividing your progress bar by the total number of bytes to be loaded by the size of the chunks of the file you are reading with each read() call.

If you are using asynchronous reads, then your progress loop would check the status of any completed reads and update the progress for each file that finished.

If you are reading a huge number of files, you might update your progress after each file read.

A progress bar should be more than an animation, it should let you (and the user) know that the application is still processing data and has not locked up. If your progress bar is just some animation that is disassociated from the actual loading process going on, then when something goes wrong with the real file reading, your progress bar will just sit there and continue to run and you (and the user) will never know something is really going wrong.

Matthew
Was This Post Helpful? 0
  • +
  • -

#3 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Animations in Allegro

Posted 24 January 2009 - 09:03 PM

"your progress bar will just sit there and continue to run and you will never know something is really going wrong."

Hi Windows 95!

This post has been edited by Hyper: 24 January 2009 - 09:03 PM

Was This Post Helpful? 0
  • +
  • -

#4 NuclearPeon  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 08-January 09

Re: Animations in Allegro

Posted 25 January 2009 - 01:33 AM

I think a good rule of thumb to follow is always have a status bar or some sort of minimal text output along with a progress bar.
Was This Post Helpful? 0
  • +
  • -

#5 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Animations in Allegro

Posted 25 January 2009 - 02:16 AM

Whose thumb?
Was This Post Helpful? 0
  • +
  • -

#6 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: Animations in Allegro

Posted 25 January 2009 - 08:07 AM

Yeah this is kind of what I'm curious about, how do you make animations, Of course I would add text with it, like at the beginning it might say Loading Libraries... and the say Loading Images... or something like that. But how do I make animation without having it display a gif image?
Was This Post Helpful? 0
  • +
  • -

#7 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: Animations in Allegro

Posted 25 January 2009 - 11:31 AM

Come on anyone know how to make an animation in Allegro?
Was This Post Helpful? 0
  • +
  • -

#8 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Animations in Allegro

Posted 25 January 2009 - 05:59 PM

Think about what you're asking. What is an "animation?"
It's a series of pictures being displayed side by side, of course. How do you think *.gif images work?
Was This Post Helpful? 0
  • +
  • -

#9 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: Animations in Allegro

Posted 26 January 2009 - 05:13 AM

Yes, though how do I make Allegro change the previous images?
Was This Post Helpful? 0
  • +
  • -

#10 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Animations in Allegro

Posted 26 January 2009 - 06:29 AM

How did you make it load the first image?
Simply make another image and load that consecutively afterwards.
Was This Post Helpful? 0
  • +
  • -

#11 matthew180  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 07-January 09

Re: Animations in Allegro

Posted 26 January 2009 - 08:35 AM

The animation part can be done one of two ways:

Pre-made images:

1. Create a series of images that make up your animation.
2. Load all the images (Allegro might have a sprite system that assists with this.)
3. Draw the first image.
4. Wait a certain amount of time (depends on your animation.)
5. Draw the next image at the same x,y location as the previous image, i.e. replace it on the screen.
6. When you get to the last image, start over with the first image.

The images that make up your animation need to be such that the last one seamlessly transitions to the first, otherwise at the end of the sequence you will get a jerky sort of unnatural motion (it will look bad.)

Also, in step 4, it would be best to mix real-time along with monitoring that something is actually happening with the data (see my first post.) If you use time alone to update the animation then, as I said before, it will continue to play and not provide any feedback as to what is really going on.

If you know the size of the data and can make a 0% to 100% *linear* progress bar, then do that. Otherwise, use a spinner type of indicator which tells you that something is happening, but you don't know when it will be done. If the data stops flowing, the progress bar / spinner should stop working too.


Second method - programmatically generate images. This is almost the same as the pre-made animation except that you generate the images of the animation at runtime. You do this by allocating an image buffer and using drawing commands (line, pixels, shapes, etc.) to draw on "onto" the image buffer instead of the screen buffer. When the image is done, you draw (blit) it to the screen just like an image you loaded.

Usually the sequence you are generating would be controlled by an algorithm or something, like animating a sine wave or some mathematical formula. Although, if you were making a 0% to 100% progress bar, you could use this to draw the progress. However, you can also use an image and clipping to draw the progress bar as well.

Matthew
Was This Post Helpful? 0
  • +
  • -

#12 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Animations in Allegro

Posted 26 January 2009 - 11:39 AM

Thanks Einstein, now he won't think and learn. :(
I was trying to stimulate his only brain-cell dude.
Was This Post Helpful? 0
  • +
  • -

#13 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: Animations in Allegro

Posted 28 January 2009 - 05:25 AM

I recently thought that I needed the images to replace each other. Now the question is how do I set a timer?
Was This Post Helpful? 0
  • +
  • -

#14 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Animations in Allegro

Posted 28 January 2009 - 09:53 AM

They do "replace" each other. If you want a better understanding or idea, try to "animate" stuff on paper.

How do you set a timer? One method (on Windows, using the Win32 API) is to use the "Sleep" call.

Example of usage: Sleep(1000); will cause the program to pause for 1 second (1000ms)
Was This Post Helpful? 0
  • +
  • -

#15 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: Animations in Allegro

Posted 28 January 2009 - 04:04 PM

OK, that helps, but what Library do I need to do that?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3