Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stardust on Sat 15/11/2014 18:31:53

Title: [SOLVED] Problem rendering a DynamicSprite with alpha
Post by: Stardust on Sat 15/11/2014 18:31:53
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.

(http://s14.postimg.org/6i0c0d8ip/ags.jpg)

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) Select

    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
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Crimson Wizard on Sat 15/11/2014 18:52:58
What version of AGS?
Is your game 32-bit?
Do you import the sprites with alpha channel?
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Stardust on Sat 15/11/2014 19:05:26
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!
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Crimson Wizard on Tue 18/11/2014 08:32:00
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"?
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Stardust on Tue 18/11/2014 15:11:59
It was set to proper alpha blending
I just tried classic to see what it does but I get the exact same result.
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: 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).

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.
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Monsieur OUXX on Tue 18/11/2014 15:58:28
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.
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Crimson Wizard on Tue 18/11/2014 16:04:33
Sorry, misread previous post. [post deleted]
Yes, its like Monsieur OUXX sais.
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Snarky on Tue 18/11/2014 17:02:40
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
Title: Re: Problem rendering a DynamicSprite with alpha
Post by: Stardust on Thu 20/11/2014 18:58:02
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.