TransparentSprite with color : 0

Just starting out? Need help? Post your questions and find answers here.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 609
Joined: Tue Jan 04, 2011 6:21 pm

TransparentSprite with color : 0

Post by SPH »

Hi,

I'm banging my head against the wall because the transparency system has become so complicated.
Could you please correct this code so that transparency is applied to the black color (RGB(0,0,0))?
This was the usual color when we coded in PB6.12 or earlier.

Many thanks

Code: Select all

InitSprite()

OpenScreen(1920,1080,32,"Sprite")

 ;Création du sprite
CreateSprite(1,1920,1080)
StartDrawing(SpriteOutput(1))
r=Random(55)
v=Random(55)
b=Random(55)
r2=Random(1)*2-1
v2=Random(1)*4-2
b2=Random(1)*6-3

For i=0 To 1079
  LineXY(0,i,1920,i,RGB(r,v,b))
  r+r2
  If r>100 Or r<0
    r2*-1
    r+r2
  EndIf
  v+v2
  If v>100 Or v<0
    v2*-1
    v+v2
  EndIf
  b+b2
  If b>100 Or b<0
    b2*-1
    b+b2
  EndIf
Next
  StopDrawing()
  
  
  CreateSprite(0,201,201,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_Gradient)      
BackColor(RGB(255,255,255))
FrontColor(RGB(255,255,0))     
CircularGradient(100, 100, 100)     
Circle(100, 100, 100)
CircularGradient(350, 100, 75)
Circle(300, 100, 100)
StopDrawing()


 ;Affichage du sprite
  
  DisplaySprite(1,0,0)
  DisplayTransparentSprite(0, 210, 160)

FlipBuffers()
Delay(3000)


!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 6064
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: TransparentSprite with color : 0

Post by idle »

Code: Select all

InitSprite()

OpenScreen(1920,1080,32,"Sprite")

 ;Création du sprite
CreateSprite(1,1920,1080)
StartDrawing(SpriteOutput(1))
r=Random(55)
v=Random(55)
b=Random(55)
r2=Random(1)*2-1
v2=Random(1)*4-2
b2=Random(1)*6-3

For i=0 To 1079
  LineXY(0,i,1920,i,RGB(r,v,b))
  r+r2
  If r>100 Or r<0
    r2*-1
    r+r2
  EndIf
  v+v2
  If v>100 Or v<0
    v2*-1
    v+v2
  EndIf
  b+b2
  If b>100 Or b<0
    b2*-1
    b+b2
  EndIf
Next
  StopDrawing()
  
  
CreateSprite(0,201,201, #PB_Sprite_AlphaBlending | #PB_Sprite_Transparent )
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_Gradient | #PB_2DDrawing_AlphaBlend )      
BackColor(RGBA(255,255,255,255))
FrontColor(RGBA(255,255,0,255))     
CircularGradient(100, 100, 100)     
Circle(100, 100, 100)
CircularGradient(350, 100, 75)
Circle(300, 100, 100)
StopDrawing()


 ;Affichage du sprite
  
  DisplaySprite(1,0,0)
  DisplayTransparentSprite(0, 210, 160)

FlipBuffers()
Delay(3000)


User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 425
Joined: Thu Jul 09, 2015 9:07 am

Re: TransparentSprite with color : 0

Post by pf shadoko »

Yeah, that's new.
Now you have to specify “#PB_Sprite_Transparent”
and the default drawing mode set the alpha to 0.
I don't know why Fred did that.
:shock:

I think you can file a bug report.
That will at least clarify the issue.

Code: Select all

InitSprite()

Debug OpenScreen(1600,900,32,"Sprite")

 ;Création du sprite
CreateSprite(1,1600,900)
StartDrawing(SpriteOutput(1))
r=Random(55)
v=Random(55)
b=Random(55)
r2=Random(1)*2-1
v2=Random(1)*4-2
b2=Random(1)*6-3

For i=0 To 1079
  LineXY(0,i,1920,i,RGB(r,v,b))
  r+r2
  If r>100 Or r<0
    r2*-1
    r+r2
  EndIf
  v+v2
  If v>100 Or v<0
    v2*-1
    v+v2
  EndIf
  b+b2
  If b>100 Or b<0
    b2*-1
    b+b2
  EndIf
Next
  StopDrawing()
  
  
CreateSprite(0,201,201,#PB_Sprite_AlphaBlending|#PB_Sprite_Transparent)
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels|#PB_2DDrawing_Gradient)      
BackColor(RGBA(255,255,255,255))
FrontColor(RGBA(255,255,0,255))     
CircularGradient(100, 100, 100)     
Circle(100, 100, 100)
CircularGradient(350, 100, 75)
Circle(300, 100, 100)
StopDrawing()


 ;Affichage du sprite
  
  DisplaySprite(1,0,0)
  DisplayTransparentSprite(0, 210, 160)

FlipBuffers()
Delay(3000)

User avatar
SPH
Enthusiast
Enthusiast
Posts: 609
Joined: Tue Jan 04, 2011 6:21 pm

Re: TransparentSprite with color : 0

Post by SPH »

"Not clear" doesn't mean "bug."
But there are several parameters to manage, and it's not intuitive...

Thanks, guys, for your reply.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
SPH
Enthusiast
Enthusiast
Posts: 609
Joined: Tue Jan 04, 2011 6:21 pm

Re: TransparentSprite with color : 0

Post by SPH »

The problem is slightly different, but this time it's a color issue. Specifically, I'm drawing lines in several different colors:

Code: Select all

  LineXY(Random(1920),400+Random(1080),Random(1920),400+Random(1080),RGB(Random(255),Random(255),Random(255)))  
Yet, they come out in white! That too is very counter-intuitive and incredibly frustrating...

Code: Select all

InitSprite()

OpenScreen(1920,1080,32,"Sprite")

;Création du sprite
CreateSprite(1,1920,1080)
StartDrawing(SpriteOutput(1))
r=Random(55)
v=Random(55)
b=Random(55)
r2=Random(1)*2-1
v2=Random(1)*4-2
b2=Random(1)*6-3

For i=0 To 1079
  LineXY(0,i,1920,i,RGB(r,v,b))
  r+r2
  If r>100 Or r<0
    r2*-1
    r+r2
  EndIf
  v+v2
  If v>100 Or v<0
    v2*-1
    v+v2
  EndIf
  b+b2
  If b>100 Or b<0
    b2*-1
    b+b2
  EndIf
Next
StopDrawing()

;;;;;;;;;;;
CreateSprite(0,1920,1080,#PB_Sprite_AlphaBlending | #PB_Sprite_Transparent )
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_Gradient | #PB_2DDrawing_AlphaBlend )      
For i=1 To 100
  LineXY(Random(1920),400+Random(1080),Random(1920),400+Random(1080),RGB(Random(255),Random(255),Random(255)))  
Next
StopDrawing()

;;;;;;;;;;;



;Affichage du sprite

DisplaySprite(1,0,0)
DisplayTransparentSprite(0, 0, 0)

FlipBuffers()
Delay(2400)

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 6064
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: TransparentSprite with color : 0

Post by idle »

that's the gradient flag causing the issue

Code: Select all

;;;;;;;;;;;
CreateSprite(0,1920,1080,#PB_Sprite_AlphaBlending | #PB_Sprite_Transparent )
StartDrawing(SpriteOutput(0))
DrawingMode( #PB_2DDrawing_AlphaBlend )      
For i=1 To 100
  LineXY(Random(1920),400+Random(1080),Random(1920),400+Random(1080),RGBA(Random(255),Random(255),Random(255),255))  
Next
StopDrawing()

;;;;;;;;;;;
User avatar
SPH
Enthusiast
Enthusiast
Posts: 609
Joined: Tue Jan 04, 2011 6:21 pm

Re: TransparentSprite with color : 0

Post by SPH »

Thx. All codes is OK now

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Post Reply