hey, i use a custom sprite animation architecture making use of allegro datafiles and properties.
Now I realise that Allegro 5 doesn't have datafiles, which is fine, since you can use .zip files. but it now means I can't use my animation architecture.
I still want to use the animation architecture, so i'm developing a little utility that'll extract the sprite frames and properties from the datafile and pack them into a nice little binary file that can be loaded from the zip. Progress is being made, but I have a bottleneck i need to get around.
This is how the utility saves the bitmap data:
Just so you know, the pStream variable is a pointer to a std::ofstream instance.
That seems to work. But now I'm working on the allegro 5 code to load these files. But all it displays is a black box. The allegro 5 reverse code is shown below:
Obviously this doesn't work. Is there another way? Help would be appreciated.
A) Why are you writing chars with the length of an integer? (Or are r,g,b,a actually integers?)
B) You probably want to lock the bitmap and use al_put_pixel to copy the data as-is without any blending.
update:
i fixed the problem. It wasn't a problem with my loading code, it was with my drawing code. i had to set up alpha-blending properly.
but there's still an issue.
i do the animation in the form of a filmstrip, and i draw each frame as a segment of the bitmap. But al_draw_bitmap_region doesn't seem to have the same properties as blit, since it doesn't draw a region of the bitmap as much as it draws the strip sequentially across the screen. also, it doesn't mask pink colour. am i doing something wrong?
this is the drawing code.
But al_draw_bitmap_region doesn't seem to have the same properties as blit, since it doesn't draw a region of the bitmap as much as it draws the strip sequentially across the screen. also, it doesn't mask pink colour. am i doing something wrong?
What do you mean it draws the strip sequentially across the screen? It should only draw one region at a time, which you specify.
Allegro 5 doesn't understand/use magic pink anymore. You need to use al_convert_mask_to_alpha on your sprite sheets.
What does this mean?
al_set_blender( ALLEGRO_ADD, iAlpha, 255 - iAlpha );
The second and third parameters must be one of:
ALLEGRO_ZERO
ALLEGRO_ONE
ALLEGRO_ALPHA
ALLEGRO_INVERSE_ALPHA
ignore the alpha thing.
What i mean is that, it only draws the first frame of the strip, and tiles it in a line across the screen.
how do the coordinates for al_draw_bitmap_region work? they're float values, so are they fractions or something?
Maybe m_dwFrameIndex is always 0.
Everything that respects the transformations uses floats. If you aren't using any transformations, then they work just like the Allegro 4 coordinates when blitting.
no the m_dwFrameIndex is incrementing.
the actual argument descriptions for the function are a little ambiguous. I've been tweeking them, and I'm able to stop the thing from tiling, but its not showing the frame indicated by the frame index counter. where is there a concise description for the arguments for drawing bitmap regions?
EDIT:
Problem solved. Thanks guys!
But i have to ask something: how does transparency work in allegro 5? it's not as well described in the documentation as in allegro 4
What i mean is that, it only draws the first frame of the strip, and tiles it in a line across the screen.
So you're saying that what it draws is wider and/or taller than the width and height you passed to the al_draw_bitmap_region function? That sounds like something is wrong with the function then. Make sure the width and height values are correct.
where is there a concise description for the arguments for drawing bitmap regions?
check my last edited post.
i fixed it. there was a problem with my loading code, but it's fixed.
now all i'd like to know is how transparency works in allegro 5.
It uses the alpha channel.
Set the alpha channel to 0 on the pixels you don't want it to draw, and it won't draw them.
no the masking problem is solved. in allegro 4 i used to be able to draw bitmaps translucently by setting a transparency blender. allegro 5 doesn't seem to have that from my studies of the documentation
alpha 0 indicates fully transparent, alpha 255 indicates fully opaque. How bitmaps are drawn depends on the blender in use. A5 uses premultiplied alpha by default, which means you have to scale the rgb values that you pass to functions by the alpha value, or else change the blender.
i used to be able to draw bitmaps translucently by setting a transparency blender. allegro 5 doesn't seem to have that from my studies of the documentation
Use al_draw_tinted_bitmap(bitmap , al_map_rgba_f(1.0f , 1.0f , 1.0f , 0.5f) , x , y , 0); to draw at 50% opacity.
What effect do you want?
If using the default pre-multiplied alpha blender, then something like this will draw at 50%:
al_draw_tinted_bitmap(bitmap, al_map_rgba_f(0.5, 0.5, 0.5, 0.5), x, y, 0);