[SOLVED] BUG: GUI background graphic switch between alpha/non-alpha sprites?

Started by monkey0506, Fri 16/01/2009 18:57:24

Previous topic - Next topic

monkey0506

I'm using AGS 3.1.2, but IIRC this used to cause me grief on prior versions of AGS as well. I'm working with the Flashlight module, and I think I've discovered a bug...I've managed to replicate the problem several times...

In the module I'm using the DrawingSurface functions to build a Dynamic sprite based on this pattern:

Code: ags
Flashlight.ScreenSprite = DynamicSprite.CreateFromExisting(Flashlight.BeamSprite.Graphic, true);
Flashlight.ScreenSprite.Resize(FloatToInt(Flashlight.Radius * 2.0), FloatToInt(Flashlight.Radius * 2.0));
Flashlight.ScreenSprite.ChangeCanvasSize(System.ViewportWidth, System.ViewportHeight, Flashlight.X, Flashlight.Y);
DrawingSurface *surface = Flashlight.ScreenSprite.GetDrawingSurface();
// draw rectangles on each side of the sprite
surface.Release();


The problem is this, if the module is set to GUI mode:

Code: ags
Flashlight.AGSGUI.BackgroundGraphic = Flashlight.ScreenSprite.Graphic;


And then in my updating method which is called from repeatedly_execute, the GUI is turned off (whether it was on or not):

Code: ags
Flashlight.AGSGUI.Visible = Flashlight.Enabled;


Then it goes all weird.

What it's doing is this:

  • If the very first sprite (BeamSprite) drawn has an alpha channel and then I later try to switch to a sprite without an alpha channel, I get this:



    The non-alpha sprite is missing entirely. If I save the DynamicSprite to a file it appears fine (tested with both BeamSprite and ScreenSprite).

  • If the very first sprite (BeamSprite) drawn does not have an alpha channel, anything I draw that has an alpha channel then becomes flattened.

    I've spent the better part of the last 2 hours debugging my code and I can't find anything wrong with it. As a matter of fact now it appears that I can only use alpha sprites if the GUI has been explicitly turned off, otherwise they're all now being flattened. But if I do turn it off, then non-alpha sprites disappear entirely. >:(

Pumaman

I'm not really sure where you're saying the problem is, or what exactly is and shouldn't be happening... would you be able to upload a game source that demonstrates the problem?

monkey0506

What is happening is this:

If I draw a sprite with no alpha channel onto a DrawingSurface of a DynamicSprite and then set that DynamicSprite to the BackgroundGraphic of a GUI, the sprite itself disappears entirely. Or if I'm drawing one with an alpha channel, the sprite is flattened. Depending upon whether the GUI has previously been explicitly turned off. Apparently.

The source is here.

The offending line is apparently line 139 of Flashlight.asc which reads:

Code: ags
if (this.IsGUIMode) this.AGSGUI.Visible = false;


Which turns the GUI off if the effect is disabled and was using a GUI. Uncommented it allows only alpha sprites (non-alpha disappear). Commented it allows non-alpha sprites, but any alpha sprites are flattened.

Pumaman

Thanks for uploading it, but can you provide some instructions on how to reproduce the problem? When running the game, what do you press/click, what do you see, and what should you see instead?

monkey0506

Oh sorry. :P

Numbers 1-4 cycle between different beam-sprites:

1. "flashlight.bmp", no alpha
2. crappy attempt at alpha dithering
3. alpha smoothed circle
4. red alpha smoothed circle

The problem is that either #1 works properly and #2-4 become flattened, or #2-4 work properly and #1 the entire sprite disappears (see screenshot above). As I said this is apparently controlled by whether the GUI is allowed to be turned off. Thanks for looking into this...

Pumaman

Thanks for reporting this. I've investigated and there is indeed a bug with the DX5 driver switching a GUI background graphic from one with to one without an alpha channel, and vice versa.

I'll get it fixed, but in the meantime a workaround to see it working properly would be to use the D3D driver.


SMF spam blocked by CleanTalk