Page 1 of 1
DrawAlphaImage - drawing in wrong order
Posted: Tue Jul 15, 2025 5:43 pm
by KianV
Hi all,
I have created 4 transparent images which need to be layered in a specific order.
When I draw them onto the background using the following code:
Code: Select all
DrawAlphaImage(ImageID(#calque1),(188),100)
DrawAlphaImage(ImageID(#calque2),(188),100)
DrawAlphaImage(ImageID(#calque3),(188),100)
DrawAlphaImage(ImageID(#calque4),(188),100)
the final layer 'calque4' always appears behind the others.
I have even tried drawing layer 4 onto layer 3 first, but still the same behaviour
Can anyone provide an explanation for this ?
Thanks in advance,
Kian
Re: DrawAlphaImage - drawing in wrong order
Posted: Tue Jul 15, 2025 6:17 pm
by STARGĂ…TE
I can't confirm this report.
In this code, the drawing order is exactly the oder of the call of DrawAlphaImage()
Code: Select all
Enumeration
#Window
#Gadget
#Image1
#Image2
#Image3
#Image4
EndEnumeration
Define Image.i
For Image = #Image1 To #Image4
If CreateImage(Image, 128, 128, 32, #PB_Image_Transparent)
If StartDrawing(ImageOutput(Image))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Select Image
Case #Image1
Box(0, 0, 128, 128, $FF0000FF)
Case #Image2
Box(16, 16, 96, 96, $FF00FF00)
Case #Image3
Box(32, 32, 64, 64, $FFFF0000)
Case #Image4
Box(48, 48, 32, 32, $FF000000)
EndSelect
StopDrawing()
EndIf
EndIf
Next
OpenWindow(#Window, 0, 0, 800, 450, "Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), #PB_Canvas_Keyboard)
If StartDrawing(CanvasOutput(#Gadget))
DrawAlphaImage(ImageID(#Image1), 64, 64)
DrawAlphaImage(ImageID(#Image2), 64, 64)
DrawAlphaImage(ImageID(#Image3), 64, 64)
DrawAlphaImage(ImageID(#Image4), 64, 64)
StopDrawing()
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
End
Re: DrawAlphaImage - drawing in wrong order
Posted: Tue Jul 15, 2025 6:40 pm
by KianV
Your code works correctly for me also.
I don't know if it makes any difference but the 'background' I am merging them onto is another (non.transparent) image, rather than a canvas.
Re: DrawAlphaImage - drawing in wrong order
Posted: Tue Jul 15, 2025 6:49 pm
by Little John
As always: Posting a short executable code that demonstrates the problem would help a lot.
Re: DrawAlphaImage - drawing in wrong order
Posted: Tue Jul 15, 2025 7:38 pm
by KianV
Unfortunately I cannot create a small bit of code which does the same.
I did indeed write a small example, but it behaves exactly as it should. The program which it is part of is very large.
I was hoping that at some point someone had come across something similar and had a eureka moment.
Re: DrawAlphaImage - drawing in wrong order
Posted: Wed Jul 16, 2025 6:19 am
by IceSoft
KianV wrote: Tue Jul 15, 2025 7:38 pm
Unfortunately I cannot create a small bit of code which does the same.
I did indeed write a small example, but it behaves exactly as it should. The program which it is part of is very large.
I was hoping that at some point someone had come across something similar and had a eureka moment.
Check your code. There is the problem. I think you draw sprites anywhere again.
Re: DrawAlphaImage - drawing in wrong order
Posted: Wed Jul 16, 2025 7:11 am
by RASHAD
Hi
Most probably you have a conflict with enumeration or you are using ImageID(#calque4) in other place before or after
Check your ImageID()
Re: DrawAlphaImage - drawing in wrong order
Posted: Thu Jul 17, 2025 6:57 pm
by KianV
IceSoft was kind of right and lead me to the solution.
The code which drew the layers was erroneously called twice. The first time was after drawing the 'top' layer (calque4). Essentially the program is reversing the order of the layers, so it drew the top layer, added it to the background. cleared the layer graphics then it drew the lower layers before outputting them on top.
My thanks to everyone who contributed to what was a slightly vaguely presented problem.