Strange cannal alpha

Started by Baguettator, Tue 21/09/2021 14:22:21

Previous topic - Next topic

Baguettator

Hi again !

I come with this problem that I tried to forget because it was not so important, but at least, I'm looking for a solution, and now it's a good time to find one ! :)

I use a sprite of a clock to show the time in my game, but, I can't understand why, whereas I import my sprite with an alpha channel, in PNG, there is always an ugly "purple" thing around the clock.

Here is the result "in game" :

https://drive.google.com/file/d/1dxyvfgaK_6CG_yLeAWVGRMFprnaKiRk3/view?usp=sharing

Here are two versions of my sprite, I tried with a black "contour", and it doesn't work too.

https://drive.google.com/file/d/10CtmML7eIRf4W7IMhJoXKLR6Uhbc34Kx/view?usp=sharing

https://drive.google.com/file/d/18Eu23YQomVnGP3q4ypZWT6qxwUjgAY-x/view?usp=sharing

Any idea ? The purple is like the "magic pink" used for transparent things in AGS, but I don't why it appears like that. I tried the same sprites on a magic pink background, it didn't work...

Crimson Wizard

To clarify, this is how it looks in game or in the editor? Because editor does not draw sprites with alpha iirc.

If it's how it looks in game, then you did not import the sprite correctly. Usually for sprites with alpha channel you need to set:
* Import alpha channel
* Transparency: leave as is

Baguettator

Yeah, I know, that's just what I did !! It looks like that in game... :(

Crimson Wizard

Please tell, which settings exactly do you use when importing it.

Cassiebsg

Make sure you have proper alpha blending set for Sprite alpha rendering style (General settings) and that your game is actually 32-bit (true colour)
If that doesn't help than there are only 2 options left:

- Your sprite doesn't really have alpha.
- Or you actually missed the "Transparency: leave as is" setting. Try and re-import the sprites and make sure you select both (Note that selecting "Import alpha channel" doesn't automaticaly select "Transparency: leave as is"...
There are those who believe that life here began out there...

Baguettator

I really used "import alpha channel" and "leave at is", and my game is in 32-bit true color and I have activated proper alpha blending.

So it seems that the image has a problem. I insist that the pink appears only "around" the clock, not on the full background of the sprite.

Is there any problem with AGS ? Because the normal image is displayed normally in windows or any program that can open it, but it appears strangely in AGS ONLY.

By the way, how could I give to the clock a proper alpha channel ?

Crimson Wizard

#6
Here I imported your image into AGS game and it works fine:
https://www.dropbox.com/s/fvgcqpqcfculh0j/test--alphasprite.zip?dl=0

How exactly do you display this sprite in game?

Baguettator

#7
It's displayed in a dynamic sprite. I use a module to make a clock. From the french AGS community :

https://adventuregamestudio.1fr1.net/t1686-horloge-analogique

EDIT : it's a dynamic sprite, and this clock is drew on that dynamic sprite. Then the "needles".


eri0o

In your dynamic sprite, which value did you pass for the  hasAlphaChannel parameter?

Baguettator

In the module, I just wrote the "true" for preservealphachannel options, for both needles and clock, and, there the result : surprise !!

https://drive.google.com/file/d/1oJ6WQTR0Yybrgj4QDzuqUIaIhmWbUsrx/view?usp=sharing

Here the code of the module. It seems that the Drawing function is putting some pink at the edges of the image.

Code: ags
static DynamicSprite* Horloge::CreateFromSprites(int h, int m, int heure, int minute, int fond) {
  
  if ((heure < 1) || (minute < 1)) return null; // Il faut obligatoirement spécifier des sprites valides
    
  DynamicSprite* he = DynamicSprite.CreateFromExistingSprite(heure, true); // La sprite des heures
  DynamicSprite* mi = DynamicSprite.CreateFromExistingSprite(minute, true); // La sprite des minutes
  
  int taille; // Définira la taille de la sprite retournée
  
  int t_h = he.Height; // La hauteur de l'image de l'aiguille des heures
  int t_m = mi.Height; // La hauteur de l'image de l'aiguille des minutes
  
  if (t_h > t_m) taille = t_h * 2; // L'image la plus grande définit
  else taille = t_m * 2; // la taille de la sprite à retourner
  
  DynamicSprite* he2 = DynamicSprite.Create(taille, taille); // La sprite des heures centrées
  DynamicSprite* mi2 = DynamicSprite.Create(taille, taille); // La sprite des minutes centrées
  DrawingSurface* she2 = he2.GetDrawingSurface(); // Les surfaces correspondantes
  DrawingSurface* smi2 = mi2.GetDrawingSurface(); // Les surfaces correspondantes
  
  she2.DrawImage((taille - he.Width) / 2, taille / 2 - t_h, he.Graphic); // On centre
  smi2.DrawImage((taille - mi.Width) / 2, taille / 2 - t_m, mi.Graphic); // On centre
  
  she2.Release(); // On associe la surface obtenue à la sprite
  smi2.Release(); // On associe la surface obtenue à la sprite
  
  if (h < 0) h = 12 + h % 12; // On gère les valeurs négatives pour h
  if (m < 0) m = 60 + m % 60; // et pour m

  he2.Rotate( (((h % 12) * 30 + (m % 60) / 2) % 359) + 1 ); // On tourne (+1 car Rotate ne supporte pas la valeur 0)
  mi2.Rotate( (((m % 60) * 6) % 359) + 1 ); // De même, on module pour ne pas dépasser 359
  
  DynamicSprite* horl = DynamicSprite.Create(taille, taille); // La sprite que l'on retournera
  DrawingSurface* cadran = horl.GetDrawingSurface(); // Sa surface, sur laquelle on va dessiner les aiguilles
  
  if (fond > 0) { // On dessine le fond s'il en est spécifié un
    DynamicSprite* spr_fond = DynamicSprite.CreateFromExistingSprite(fond, true); // La sprite du slot fond
    cadran.DrawImage((taille - spr_fond.Width) / 2, (taille - spr_fond.Height) / 2, fond); // On centre le fond
  }
  
  cadran.DrawImage((taille - mi2.Width) / 2, (taille - mi2.Height) / 2, mi2.Graphic); // On dessine l'aiguille des minutes
  cadran.DrawImage((taille - he2.Width) / 2, (taille - he2.Height) / 2, he2.Graphic); // On dessine l'aiguille des heures
  
  cadran.Release(); // On associe la surface obtenue à la sprite
  
  return horl; // Et on retourne la sprite
  
}

eri0o

There's still a bunch dynamic sprites with hasAlphaChannel=false  in the code, just from a glance. :/

Crimson Wizard

Yes, you also need to do the same for calling DynamicSprite.Create, there are 3 of these in the code and they won't have alpha channel.

Baguettator

Ow.... That's true. I didn't know that I had to do that for the "Create" functions, as they were only drawing surfaces. Thanks a lot !

By the way, it's not the subject here, but I have to say that it appears in the editor some problem (or maybe not, you will tell me)  : if a function imported in a struct (this way we can use "this" related to this struct's element) is too long, the editor didn't show anymore the parameters for functions when we write "this" and then hit the "."

It's not really a big problem, but sometimes, it is annoying because you don't necessarly remember what are the parameters of the functions. Also, it doesn't display the components of the struct after the ".", after "this".

Crimson Wizard, you can have a look of that in my game, just in case of ? Go to "Struct Cartes", and at the end of the function "Cartes::CreationCartes", write something like "this.Composition()". This function has many parameters, but it is not displayed in the editor, like a help for the mind. I saw that this thing is working well at the start of the function (when the code is not too big), and until some step, it doesn't work anymore.

SMF spam blocked by CleanTalk