"新年快乐!各位!"
(happy New Year! Ladies and gentlemen!)
I would like to ask a small problem today.For newcomers, though, it is very serious.
ALLEGRO_BITMAP,Is he a "const"?(He pointed pointer)
allegro_load_bitmap,How his efficiency?How long it takes to load the image (eg 200 * 200 pixels)?
Or, if we have a lot of animated pictures.Have to use ALLEGRO_BITMAP to create a large number of pointers.
Rather than using load to quickly load.
-------------------------------------
ALLEGRO_BITMAP * running_anima[500];
This should be feasible?
ALLEGRO_BITMAP
https://www.allegro.cc/manual/5/ALLEGRO_BITMAP
typedef struct ALLEGRO_BITMAP ALLEGRO_BITMAP;
It's a struct which contains information about the bitmap you loaded, things like width, height etc.
Thanks.
eg:200*200 size,75pixel/cm
--------------------------
New proble:
I changed something, but he can not use it.
My method of using two timers is wrong.
why?
error:
abort() been xxxxxxxxx.
---------------------------------
Complete code:
With contemporary graphics hardware, it is best to arrange all animation frames in a single bitmap. This is called an "atlas bitmap". You can then either use al_draw_bitmap_region to draw the frames, or al_create_sub_bitmap to create individual bitmaps for the frames efficienly.
And a happy new year to you to!
You are mixing drawing and logic. That only causes problems. Keep your drawing code separate from your logic. Have one redraw only, not two running on separate timers or you'll get out of sequence. You can still use two timers for your logic rates, but only one timer should control the redraw.
To add to beoran's advice. You should also set up a timer so that every time the timer fires off, you update the animation (switch to the next image). You will have to decide for yourself how often you want the time to fire off.
In my Deluxe Pacman 2 game I have one large PNG image for my Pacman character in a 5x5 grid of images that make up the animation. When you are moving, the first 5 images are used and when you die, it goes through the rest.
My Allegro 5 code to load in my main pacman image, with this 5x5 grid of images is...
I then later set up a timer for the pacman animation...
// Create a timer for updating pacman movement // once InitPacman is done pacman.timer = al_create_timer(1.0f / pacman.ts); if(!pacman.timer) { // Handle errors here } al_register_event_source(event_queue, al_get_timer_event_source(pacman.timer)); al_start_timer(pacman.timer);
pacman.ts holding the speed I wish to update this.
And in my game loop event checker, I check for the timer and update pacman's animation when it fires...
case ALLEGRO_EVENT_TIMER: // PACMAN TIMER if(event.timer.source == pacman.timer) { // Do pacman stuff here }
A large number of relatives I totally can not find time.
Thank you for your help, I think I understand.
But still, the problems are always one after another.
I do not quite understand what a substantive effect locking the image is, except for faster changes.
From the Allegro wiki (https://www.allegro.cc/manual/5/al_lock_bitmap) on using al_lock_bitmap() with ALLEGRO_LOCK_READONLY as I do in my code.
“ALLEGRO_LOCK_READONLY - The locked region will not be written to. This can be faster if the bitmap is a video texture, as it can be discarded after the lock instead of uploaded back to the card.”
When you read/write a bitmap, Allegro has to update the bitmap after you are done, which takes time. If you lock it as read only, that means you won't be altering it and Allegro can simply discard it once you're done without wasting time updating it. Which makes sense.
I think I understand, thank you for teaching.
When the image is locked, the image will not be drawn, but he is in memory when it is unlocked, it will draw on the screen.