GLBasic forum

Main forum => GLBasic - en => Topic started by: ampos on 2020-May-18

Title: GRABSPRITE with transparency not working
Post by: ampos on 2020-May-18
I am trying to grab an sprite with transparency, but I have tried all combos of SETTRANSPARENCY (or no setting it) and nothing works.

The grabbed sprite always is drawn back with a black background.

Any hint?
Title: Re: GRABSPRITE with transparency not working
Post by: dreamerman on 2020-May-18
In SaveBmp alpha is checked so GrabSprite also should make use of it, but I'm not sure as never used it on larger scale. Some workaround can be using custom grabsprite routine with Sprite2Mem.
Title: Re: GRABSPRITE with transparency not working
Post by: Qedo on 2020-May-18
try so it should work
There is certainly a simpler solution, but this works.
Ciao

DRAWRECT 100,100,50,50,RGB(255,0,0)
GRABSPRITE 0,75,75,100,100
CLEARSCREEN RGB(0,0,255)
DRAWSPRITE 0,100,100
AddAlpha(0,0)
DRAWSPRITE 0,200,200
SHOWSCREEN
MOUSEWAIT
END

FUNCTION AddAlpha%:  num%,col%
LOCAL size%,i%,pix%[],sx%,sy% //,abgr%,Red%,Green%,Blue%,a%
SPRITE2MEM(pix[], num)
GETSPRITESIZE num,sx,sy
size=LEN(pix[])-1
col=bOR(col,0xff000000)
FOR i=0 TO size
   IF pix[ i ] = col
      pix[ i ] = bAND(pix[ i ],0x00ffffff)
   ENDIF
NEXT   
MEM2SPRITE(pix[], num,sx,sy)
ENDFUNCTION
Title: Re: GRABSPRITE with transparency not working
Post by: ampos on 2020-May-18
I have to check collision between two rotatory sprites (in fact, they are 8 cars, and have to check collision between each other every frame), and it is driving me crazy.

I was trying to draw, grab and check, but alphas was not there.

Also was planing to pre-render at startup time all 360º ones, for faster checking, but if alpha was not going to be there anyway, it wouldn't work.

Will try later.
Title: Re: GRABSPRITE with transparency not working
Post by: dreamerman on 2020-May-18
Consider do You really need pixel based collision checking? In my opinion in most cases it's waste of resources, for games with old school graphic it's ok but if you will use it on large sprites it just will be to much overhead.
Best would be just shape based collision checking - rotated rectangles, or even polygon based if needed because it will be fast. And any such algorithm can be easily adapted to GLB.
Still if pixel based is Your choice consider using 'mask' spites - if it's 'onescreen level' game type, have offscreen surface, draw car mask to it with proper alpha/color setup, then just check specified region if some pixels differ from main mask color - so this will be only one sprite2mem per frame for all collisions.
Title: Re: GRABSPRITE with transparency not working
Post by: Qedo on 2020-May-19
ampos, for collision see this example.
Idea by Ian Price
https://www.glbasic.com/forum/index.php?topic=9332.msg80161#msg80161
Ciao
Title: Re: GRABSPRITE with transparency not working
Post by: ampos on 2020-May-19
In the end I created an animated sprite sheet will 5º each.
Title: Re: GRABSPRITE with transparency not working
Post by: Qedo on 2020-May-19
nothing
Title: Re: GRABSPRITE with transparency not working
Post by: spacefractal on 2020-May-19
the main issue with GRABSPRITE is the command using the screen buffer to grap the graphics from and here the screen buffer does not contain any transparency anyway. this is why you dont see it. You can do that by you self with sprite2mem and such command, but they cant been used realtime throught. not for collosion detection at all.
Title: Re: GRABSPRITE with transparency not working
Post by: ampos on 2020-May-19
Quote from: spacefractal on 2020-May-19
the main issue with GRABSPRITE is the command using the screen buffer to grap the graphics from and here the screen buffer does not contain any transparency anyway. this is why you dont see it. You can do that by you self with sprite2mem and such command, but they cant been used realtime throught. not for collosion detection at all.

This has sense :)
Title: Re: GRABSPRITE with transparency not working
Post by: Kitty Hello on 2020-Jun-05
But using a screen buffer, you CAN use transparency! I did that once - just try to DRAWRECT with the transparent colour.
Title: Re: GRABSPRITE with transparency not working
Post by: spacefractal on 2020-Jun-06
but can cause some issues if you uses alpha throught. Im do only have used GRABSPRITE for uses with internal collosion in Karma Miwa on the landscape. Here im was just used two colors image.