[SOLVED] RoundBox not working in PB621

Just starting out? Need help? Post your questions and find answers here.
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

[SOLVED] RoundBox not working in PB621

Post 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.
Last edited by moulder61 on Sat Jun 14, 2025 5:34 pm, edited 1 time in total.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: RoundBox not working in PB621

Post by Fred »

Any code ?
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: RoundBox not working in PB621

Post 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
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: RoundBox not working in PB621

Post by Fred »

Please a full working snippet, it's not easy to replicate without it.
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: RoundBox not working in PB621

Post 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
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: RoundBox not working in PB621

Post 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
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: RoundBox not working in PB621

Post 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.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: RoundBox not working in PB621

Post by moulder61 »

Two versions of PB running identical code. Something has changed in Purebasic, surely?

Moulder.

Image

Image
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: RoundBox not working in PB621

Post 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
pjay
Enthusiast
Enthusiast
Posts: 251
Joined: Thu Mar 30, 2006 11:14 am

Re: RoundBox not working in PB621

Post 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
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: RoundBox not working in PB621

Post 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
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: RoundBox not working in PB621

Post 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.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: RoundBox not working in PB621

Post 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.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: RoundBox not working in PB621

Post by Caronte3D »

I think [Solved] is correct.
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: [SOLVED] RoundBox not working in PB621

Post by moulder61 »

@Caronte3D

I'll take your word for it. :D

Thanks again for your input.

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
Post Reply