My game is 32-bit and the image I want to display (slot 3) has an alpha channel. But when I call PrintImage(3); it doesn't appear. Why not?
DynamicSprite*Raw, Final;
DrawingSurface*Surface;
bool FirstPrint = true;
function PrintImage(int slot, bool space)
{
if (space) Print(" ");
if (FirstPrint) { Raw = DynamicSprite.Create(DisplayBox.Width, Game.SpriteHeight[slot]+1, true); FirstPrint = false; }
else Raw.ChangeCanvasSize(DisplayBox.Width, Raw.Height+Game.SpriteHeight[slot], 0, 0);
Surface = Raw.GetDrawingSurface(); Surface.DrawImage((DisplayBox.Width/2)-(Game.SpriteWidth[slot]/2), Raw.Height-Game.SpriteHeight[slot], slot);
Surface.Release();
if (1500 < Raw.Height) Raw.Crop(0, Raw.Height-1500, Raw.Width, 1500);
Final = DynamicSprite.CreateFromExistingSprite(23, true);
Surface = Final.GetDrawingSurface();
Surface.DrawImage(0, DisplayBox.Height-Raw.Height, Raw.Graphic);
Surface.Release();
DisplayBox.NormalGraphic = Final.Graphic;
}
The sprite I'm overlaying it on, 23, doesn't have its alpha channel enabled.
Any help please?
Hmm, a bit out of my field but did you try enabling the aplha channel on the second image or maby importing a non-alpha sprite and using the engines color-to-alpha feature?
Still not resolved ???
I'm wondering: did you retype this? Because there are typos in the code.
About the problem: does it work with images that don't have an alpha channel?
Can you explain more on what it's supposed to be doing? The whole ChangeCanvasSize (which you've spelled incorrectly plus a few others as Khris has pointed out) and what not is a little confusing.
If you use the PrintImage function multiple times the height will ever increase to Raw image height plus the sprite "slot" height as well. So it would be gigantic if used numerous times. (Edit: I actually didn't notice your Crop call below which checks if it's higher than 1500)
There's also a couple other things I'm confused with. For instance why you have a global variable for Surface? I've actually done some benchmarking and found out that it isn't noticeable if you reassign the GetDrawingSurface numerous times or not within a game loop. So you're better off with just containing the DrawingSurface variable within this function as a local variable.
Edit: You've also got PrintImage instead of void PrintImage (or function). I'm assuming this was typed by memory and not copied?
Sorry guys, when I posted the editor was on another computer so I had to indeed copy manually. I updated the first post with proper code.
The image does appear as it should if it's imported without an alpha channel, just not when it is. And it doesn't make a difference whether the canvas (sprite 23) has its alpha channel enabled or not.
The function prints an image to the display, as apposed to standard Print which adds text.
This is unfortunately a "feature" of AGS.
You cannot draw a sprite with an alpha channel to a transparent surface, then draw that to something else.
While drawing, AGS can only calculate the color of a semi-transparent pixel if there's already a colored pixel there.
At first I tried clearing Raw with color 15 (white) after it is created, this showed that AGS cleared the pixels instead of drawing the sprite.
Then I tried to use a temporary sprite and draw Raw and the new sprite to that. This worked if I again cleared the temp sprite's surface with a color before drawing to it. Which doesn't really help because as far as I understand, you want to draw Raw onto a background sprite to give the display box texture.
There are two solutions I can think of:
-Calin's AGSBlend plugin, which allows to draw semi-transparent sprites onto each other while retaining a transparent background
-buffer the last several output messages/pictures and redraw the display box in its entirety every time something is printed to it.
Ah ok, thanks Khris. It isn't a feature I intended to use a lot, but thought it would be good for displaying logos and the like. I will check out Calin's plugin though.
I just spent 30 minutes trying to figure out a problem with alpha channels, so I thought I post the solution here. The image must have an alpha channel -- when in Photoshop you get that grid background and not white or something. The part I missed was that the game *MUST* be set to 32-bit!
Without that you can load and reload the images as often as you want and it will never give you that chance to use the alpha channel. I'm sure this is in the Wiki somewhere, but I didn't find it.
- Cogliostro