Hello everyone.
I am having problems learning about moving 2D bitmaps in my game. When i load some bitmaps and i begin to move them, the performance drops dramatically. I having problems when loading backgrounds too.
I had some problems before and you helped me, i am thankful for that, but i think the best help would be if you can tell me a good wiki or documentation about all it, so i can learn and not asking everytime i dont know what to do.
I tried looking in the web, but i cant find what i need, or it was an Allegro 4 wiki, and my English is not very good, so it makes me even harder. I need a begginer's guide or something like that, so i can fill the screen with moving objects
Thanks for reading.
When i load some bitmaps and i begin to move them, the performance drops dramatically.
Yeah me too. I followed the bouncer tutorial for A5 and tried creating bitmaps in the teens and my machine nearly died. I think you need a faster machine.
Are you loading the bitmaps after you create the display?
Perhaps you are moving the bitmaps every game loop. If your application runs say 200 loops per second and you add some bitmap moving there, it will get slow. Try to move the bitmaps only every 10th loop. If this helps, you're on the right way. Next step is to put timers in your game.
This should not be a problem. With hardware accelerated drawing, you should be able to draw a background and at least a hundred sprites 60 times a second. Something else is going wrong.
Show us some code.
Oh, and don't load the bitmaps on every frame.
My main function looks like this:
I load all the bitmaps in level constructor, and it draws all bitmaps every lvl.update().
If you edit that post and format it like
<code>
Insert code here
</code>
it will look nice and pretty for us, and save some vertical space:
Example:
Edit: Let us see the code for lvl.update();
Thank you for the code boxing, i was asking how to do it
I simplify the program to try to solve my problem: my lvl.update is only a X and Y movement and a al_draw_bitmap with the bitmap of the object.
If the constructor of level loads bitmaps then it might be getting called before the display is created, and therefore would have memory bitmaps instead of video bitmaps (I think). There are a few ways you could change this if that is the case: 1. Separate the bitmap loading into a separate function and call that after the display has been created or 2. Create lvl using new so that the constructor is called at that point (don't forget to delete it). The first option is probably the better choice.
I think i load the bitmaps after creating the display, i create lvl after. The code above is what i have now. I forgot i have the line <#include "level.h"> before the main, but i think the bitmaps dont load untill you call the constructor.
Show the code for the level class, including the constructor and update functions.
My main.cpp code is:
This is the code of level.h:
And the entity.h code:
With the line 'background->draw()' disabled the movement is slow, but with it enabled the movement is about 1 FPS. With only 1 of 3 of the entities the movement is good.
Well, I'm not sure what's going wrong here. You create the display, then you make a level object, which loads all your images and creates entities from them. Then you clear and draw your background and sprites every time the timer ticks. That should all be working much faster than you say it is.
With the line 'background->draw()' disabled the movement is slow, but with it enabled the movement is about 1 FPS. With only 1 of 3 of the entities the movement is good.
So, disabling the background drawing or reducing the number of entities to 1 both speed up the drawing? Some or all of the bitmaps you loaded must be memory bitmaps. I don't know why they would be, since you used the ALLEGRO_VIDEO_BITMAP flag before loading (and it's the default anyway). Check to make sure using al_get_bitmap_flags.
Oh, and if your background covers the display (and it is solid), you don't need to clear the display then.
You could try updating your graphics drivers and see if that helps.
Thanks for your help, but it continues the same way. I update the graphics drivers, i use al_get_bitmap_flags and all bitmaps returns 1024 (ALLEGRO_VIDEO_BITMAP value) and i have tried ALLEGRO_MEMORY_BITMAP (it is suposed to be slower) and i got the same slow speed.
My graphics card is a NVIDIA GEFORCE FX 5200 with 128mb, and old one but i think it should be enough.
Yeah, your GFX card should definitely be capable of handling a background and 3 sprites.
Try running ex_draw_bitmap from the allegro binaries examples and play with the parameters a bit. See how many sprites you can draw with it before it slows down. If it works, then there is something else wrong. Do any other games / applications exhibit this behaviour on your computer?
I ran ex_draw_bitmap: i get 3FPS with 1 bitmap, 2FPS with 2 or 3 and 1FPS with 4+. Changing alpha blending or the texture do not change the results (change size to 1 with only 1 bitmap returns 5FPS).
I do not understand. Im working in another game, a shot'em up one, with a ship and some bullets and enemies in the screen (no background yet) and it is just a bit slow when the screen is full of objects. I copied the main.cpp code of this game to my actual new game, the one that gives me this problem. Maybe it is because in the first game the bitmaps are small, but in the ex_draw_bitmap they are small too...
Have you attached allegro.log anywhere that shows your video modes, etc?
Take a look to it, thanks
EDIT: I had been trying to solve the problem all the morning, trying some changes, but i can´t solve it. I tried an animation and it was ok, fast and very fast if i put 120FPS, but when i began to move the bitmap horizontally it was slow again.
I run the other game i am working on, and it is a bit slow too. I didnt remember before but i usually write in C++ and Allegro in my notebook, and there it was ok. Now in my PC i get this slow speed with bitmap movements.
Before i try C++ with Allegro, i programed in Fenix/Bennu and now i am taking these games to C++. When i run my old games in Bennu, they are ok, perfect speed, so i think it is not a problem of my computer. Anyway, my computer is: AMD 3200 2GHZ, 2GB DDR and NVIDIA GEFORE 5200 128MB (drivers updated to last version). I have DirectX 9.0c, and i dont know if it has something more that should be important.
I still need your help. Without it i am lost and i am sorry for that but i would have to leave Allegro and try other libraries.