GRABSPRITE with transparency not working

Previous topic - Next topic

ampos

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?

dreamerman

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.
Check my source code editor for GLBasic - link Update: 20.04.2020

Qedo

#2
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

ampos

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.

dreamerman

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.
Check my source code editor for GLBasic - link Update: 20.04.2020

Qedo


ampos

In the end I created an animated sprite sheet will 5º each.

Qedo


spacefractal

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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

ampos

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 :)

Kitty Hello

But using a screen buffer, you CAN use transparency! I did that once - just try to DRAWRECT with the transparent colour.

spacefractal

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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/