Author Topic: GRABSPRITE with transparency not working  (Read 364 times)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
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?
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 365
    • View Profile
    • my personal website
Re: GRABSPRITE with transparency not working
« Reply #1 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.
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 265
  • UNUS SED LEO
    • View Profile
Re: GRABSPRITE with transparency not working
« Reply #2 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
« Last Edit: 2020-May-18 by Qedo »

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
Re: GRABSPRITE with transparency not working
« Reply #3 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.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 365
    • View Profile
    • my personal website
Re: GRABSPRITE with transparency not working
« Reply #4 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.
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 265
  • UNUS SED LEO
    • View Profile
Re: GRABSPRITE with transparency not working
« Reply #5 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

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
Re: GRABSPRITE with transparency not working
« Reply #6 on: 2020-May-19 »
In the end I created an animated sprite sheet will 5º each.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 265
  • UNUS SED LEO
    • View Profile
Re: GRABSPRITE with transparency not working
« Reply #7 on: 2020-May-19 »
nothing

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3925
    • View Profile
    • Space Fractal
Re: GRABSPRITE with transparency not working
« Reply #8 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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
Re: GRABSPRITE with transparency not working
« Reply #9 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 :)
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10746
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: GRABSPRITE with transparency not working
« Reply #10 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.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3925
    • View Profile
    • Space Fractal
Re: GRABSPRITE with transparency not working
« Reply #11 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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.