[SOLVED] Problem rendering a DynamicSprite with alpha

Started by Stardust, Sat 15/11/2014 18:31:53

Previous topic - Next topic

Stardust

Hey there

I need to display an image on the screen which I need to be able to rotate, given any angle I want.
From the manual, I figured the only way to do this is to put the image as an object into the scene, then create a DynamicSprite from it, rotate it, and render it.

The problem I have is that when I use a DynamicSprite, the rendering is all messed up.



The middle image ("expected"), is what I get when I add the image to the scene as an object (the result I want).
The image on the right, is what I get when I use a DynamicSprite. As you can see, the edges don't look right. It seems a DS has a trouble dealing with alpha.

Here's my code:

Code: ags

    DynamicSprite* dsBigRocket;

    DrawingSurface* surface = Room.GetDrawingSurfaceForBackground();
        
    dsBigRocket = DynamicSprite.CreateFromExistingSprite(oBigRocket.Graphic, true);

    surface.DrawImage(
        1024 / 2 - dsBigRocket.Width / 2, 
        768 / 2 - dsBigRocket.Height / 2, 
        dsBigRocket.Graphic, 
        0);
        
    surface.Release();


I've also tried copying the transparency mask after creating the DynamicSprite but I get the same result.

What I my doing wrong?
Is there any other way to freely rotate an image and have it rendered correctly? I've been searching through the manual but couldn't find anything...


Thankies

Crimson Wizard

What version of AGS?
Is your game 32-bit?
Do you import the sprites with alpha channel?

Stardust

QuoteAGS Editor .NET (Build 3.3.2.0)
v3.3.2, September 2014

It says also says "Editor version 3.3"

And yes, my game is 32bits and I imported the sprite with the alpha channel. I suppose it wouldn't be displayed right as an object otherwise?
Thanks for the fast reply!

Crimson Wizard

Something I forgot to ask.
In General Settings, Visuals category, there's "Sprite alpha rendering style" option. Is it set to "Proper alpha blending" or "Classic"?

Stardust

It was set to proper alpha blending
I just tried classic to see what it does but I get the exact same result.

Crimson Wizard

#5
Ok, I got it.
There's a restriction in AGS (or rather lack of feature), it does not apply alpha blending if the drawing surface said to have no alpha channel, and room surface does not.

I think I fixed that recently in 3.4.0 (alpha) version (but it needs to be tested first).

For 3.3.2 there might be some workaround. First of all, you said you want to display it "on screen". Perhaps you do not need to draw it on the room background? Maybe you could draw on GUI, or Overlay?

Or, you may create intermediate dynamic sprite, draw everything you want on that, then assign that sprite to a room object.

Monsieur OUXX

#6
More generally, I've grown accustomed to the following reflex: when some alpha blending goes wrong, always check the color-detph (and alpha, where it applies) of: 1) the game, 2) the rendered sprite 3) The sprite onto which it gets rendered (e.g. the background image). The culprit is almost always one of them, especially the last one, that might be 16 or 24 bits since that's how most default game templates were created.
When everything is 32-bits with alpha, there's no problem.
 

Crimson Wizard

#7
Sorry, misread previous post. [post deleted]
Yes, its like Monsieur OUXX sais.

Snarky

Quote from: Crimson Wizard on Tue 18/11/2014 15:37:41
Ok, I got it.
There's a restriction in AGS (or rather lack of feature), it does not apply alpha blending if the drawing surface said to have no alpha channel, and room surface does not.

I think I fixed that recently in 3.4.0 (alpha) version (but it needs to be tested first).

Related to this: http://www.adventuregamestudio.co.uk/forums/index.php?topic=49019.msg636468678#msg636468678

Stardust

Great!
Thanks a lot for your help guys!

I think it'd be worth mentioning this pitfall in the documentation though, cause I wrote my code based on the example given for the DynamicSprite and it was rendered to the room's background. Vicious trap.


Anyways, thanks!
I changed the thread icon to a happy face.

SMF spam blocked by CleanTalk