Page 1 of 1

[SOLVED] RoundBox not working in PB621

Posted: Fri Jun 13, 2025 2:36 pm
by moulder61
Hi #PB_All

I don't know if this is a bug or not but I wasn't sure where to ask this question? I was using PB 611 until today when I changed to the latest PB621.

I'm writing a sprite based game in which I have some sprites that are boxes with rounded corners. These are sprites created at runtime and drawn to via StartDrawing etc, rather than sprites I made myself in Inkscape for example.

It works fine in PB611 but not in PB 621. I'm using Void Linux and the Ubuntu 24.04 x64 version of PB.

Any ideas?

Thanks,

Moulder.

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 2:39 pm
by Fred
Any code ?

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 3:54 pm
by moulder61
Hi Fred,

This is a typical sprite creation block of code that I'm using:

Code: Select all

CreateSprite(#GridBG, GridW + Border * 2, GridH + Border * 2, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(#GridBG))
DrawingMode(#PB_2DDrawing_AlphaChannel)
RoundBox(0, 0, GridW + Border * 2, GridH + Border * 2, 10, 10, $FF000000)
StopDrawing()
The sprites don't all have DrawingMode(#PB_2DDrawing_AlphaChannel), some have DrawingMode(#PB_2DDrawing_AlphaBlend). I can't remember why, I haven't looked at the code for a while, but I think it was to do with cutting a hole in the sprite?

Anyway, here are a couple of images using the same code on PB611 and PB621. The one with square corners is PB621.

Moulder.

Image
Image

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 4:54 pm
by Fred
Please a full working snippet, it's not easy to replicate without it.

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 5:52 pm
by moulder61
Hi Fred,

I took the RoundBox example in the help and added a bit of my code(sort of). It seems to display the same behaviour i.e. it works in 611 not 621.

Moulder.

Code: Select all

InitSprite()

If OpenWindow(0, 0, 0, 500, 500, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, 500, 500)
  CreateSprite(0, 300, 150, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(0))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    RoundBox(0, 0, 300, 150, 8, 8, $bb000000)
  StopDrawing()
  
  
  Repeat
    ClearScreen(RGB(255,255,255))
    DisplayTransparentSprite(0, 100, 175)
    FlipBuffers()
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow  
  
EndIf

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 9:36 pm
by Caronte3D
Hi, playing with it I think you can draw the round corner sprites:

Code: Select all

InitSprite()

If OpenWindow(0, 0, 0, 500, 500, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, 500, 500)
  
  CreateSprite(0, 300, 150, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(0))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    RoundBox(0, 0, 300, 150, 18, 18, RGBA(255,0,0,255))
  StopDrawing()
  
  Repeat  
    Event = WindowEvent()
    
    ClearScreen(RGB(255,255,255))
    TransparentSpriteColor(0, #Black)

    DisplayTransparentSprite(0, 100, 175)
    DisplayTransparentSprite(0, 130, 205)
    FlipBuffers()
    
  Until Event = #PB_Event_CloseWindow  
  
EndIf

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 11:11 pm
by moulder61
@Caronte3D

That looks interesting, thanks.

My code worked fine before, nothing has changed except that I started using PB621 after being on PB611 for quite a while.

Unfortunately, I want a black box with rounded corners, not a red one!

I tried modifying your code, but I don't seem to be able to get it working how I want?

Thanks anyway.

Moulder.

Re: RoundBox not working in PB621

Posted: Fri Jun 13, 2025 11:33 pm
by moulder61
Two versions of PB running identical code. Something has changed in Purebasic, surely?

Moulder.

Image

Image

Re: RoundBox not working in PB621

Posted: Sat Jun 14, 2025 6:12 am
by Caronte3D
moulder61 wrote: Fri Jun 13, 2025 11:11 pm Unfortunately, I want a black box with rounded corners, not a red one!

Code: Select all

InitSprite()

If OpenWindow(0, 0, 0, 500, 500, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, 500, 500)
  
  CreateSprite(0, 300, 150, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(0))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    RoundBox(0, 0, 300, 150, 18, 18, RGBA(255,0,0,255))
  StopDrawing()
  
  Repeat  
    Event = WindowEvent()
    
    ClearScreen(RGB(255,255,255))
    TransparentSpriteColor(0, #Black)

    DisplayTransparentSprite(0, 100, 175,255,#Black)
    DisplayTransparentSprite(0, 130, 205,255,#Black)
    FlipBuffers()
    
  Until Event = #PB_Event_CloseWindow  
  
EndIf

Re: RoundBox not working in PB621

Posted: Sat Jun 14, 2025 6:18 am
by pjay
The new #PB_Sprite_Transparent flag should be used in v6.21 & you should alse remove the TransparentSpriteColor(), works here on Windows.

Code: Select all

InitSprite()

If OpenWindow(0, 0, 0, 500, 500, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, 500, 500)
  
  ; >>>>> new flag on CreateSprite() - #PB_Sprite_Transparent
  CreateSprite(0, 300, 150, #PB_Sprite_AlphaBlending|#PB_Sprite_Transparent)
  StartDrawing(SpriteOutput(0))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  RoundBox(0, 0, 300, 150, 18, 18, $BB000000)
  StopDrawing()
  
  Repeat  
    Event = WindowEvent()
    ;>>>> Removed: TransparentSpriteColor(0, #Black)
    ClearScreen(RGB(255,255,255))
    DisplayTransparentSprite(0, 100, 175)
    DisplayTransparentSprite(0, 130, 205)
    FlipBuffers()
  Until Event = #PB_Event_CloseWindow  
EndIf


Edit: See Freds' post here: viewtopic.php?p=640126&hilit=PB_Sprite_ ... nt#p640126

Re: RoundBox not working in PB621

Posted: Sat Jun 14, 2025 7:16 am
by Caronte3D
pjay wrote: Sat Jun 14, 2025 6:18 am See Freds' post here: viewtopic.php?p=640126&hilit=PB_Sprite_ ... nt#p640126
I missed it.
Thanks! :D

Re: RoundBox not working in PB621

Posted: Sat Jun 14, 2025 1:45 pm
by moulder61
@pjay

Thanks for the explanation, that's very helpful. I vaguely remember hearing something about transparent sprites. In Caronte3D's example, I did wonder how setting the transparent colour to black would allow me to have a black box?

@Caronte3D

Thanks for your help. Kudos for getting it working even though it wasn't the "correct" way. I like people that think outside the box. :P

See what I did there? :wink:

Moulder.

Re: RoundBox not working in PB621

Posted: Sat Jun 14, 2025 2:06 pm
by moulder61
@Anyone that knows

I wasn't sure if it was a bug in the first place, but it turns out it was a change to the way PB 621> handles transparent sprites, so should I mark this thread as "SOLVED" or "I SHOULD HAVE RTFM" or what?

Thanks,

Moulder.

Re: RoundBox not working in PB621

Posted: Sat Jun 14, 2025 4:22 pm
by Caronte3D
I think [Solved] is correct.

Re: [SOLVED] RoundBox not working in PB621

Posted: Sat Jun 14, 2025 5:35 pm
by moulder61
@Caronte3D

I'll take your word for it. :D

Thanks again for your input.

Moulder.