Round Mask of a Sprite

Previous topic - Next topic

spudgunjake

I need to grab a sprite from a background image , thats easy done, but I need to make it to display a round sprite not square Just like on the iphone when selecting text you get a round select tool.


in other words I need the  hole in the middle to be my sprite.

please help.



Hemlos

#1
Place this over your image....it is 128x128, you might need to adjust the size.
The edges are black, this you might also need to change this.

If you need it to be 32x32, edit in mspaint, and stretch/skew 25% 25%
If you need it to be 64x64, edit in mspaint, and stretch/skew 50% 50%
Dont resize it too much, you might introduce aliasing and get pink edge outline.
Best to start a new one the size you need it.

Edit: A better Alternate Solution for a circular sprite in my message below, has a sample attached to it.

[attachment deleted by admin]
Bing ChatGpt is pretty smart :O

spudgunjake

before going down the road  with this png file  is it going to allow me to have a round sprite or just a square with a hole in the middle showing the back ground.

spudgunjake

I think you missed understood me.  but thanks, john

Moru

To grab a round sprite you need to color the part you don't want with the color for transparency. For example if you use the sprite hemlos posted, you set the transparency color to pink and draw it over the selection, then you change the transparency color to black and grab the sprite. This will make the black circle transparent but also any black colors in your sprite. Best would probably be to invert the colors, the outline of the circle in pink and center in black.

spudgunjake

I see, I will try and have a go, Many thank to both of you.

spudgunjake

still no luck, heres the code, sorry for being a ass,  but still not working, help

      SETTRANSPARENCY RGB(255,0,128)
      DRAWSPRITE test[PINK_HOLE].Sprite_number, test[SAS_MAIN].MouseX, test[SAS_MAIN].MouseY

      SETTRANSPARENCY RGB(0,0,0)            
      
      GRABSPRITE test[ZOOM_KEY_SPRITE].Sprite_number,test[SAS_MAIN].MouseX, test[SAS_MAIN].MouseY,22, 22

Hemlos

Here you go, this is an alternative using polyvectors...its simple and looks cool.

http://www.glbasic.com/forum/index.php?topic=3951.0
Bing ChatGpt is pretty smart :O

spudgunjake

nice code, looks really good, thanks for the help.

Hemlos

Youre welcome, glad you like it..enjoy.
Im sure ill find a good use for it as well, i am impressed with the outcome.
Bing ChatGpt is pretty smart :O

spudgunjake

I managed to do it another way. as well.

Is it true the getpixel command only gets from the back buffer and not from a virtual screen.

It would be nice to have the SETTRANSPARENCY command with work with any draw command. it would make life a lot easer

e.g drawsprite my_sprite, 0, 0, RGB(128,128,128) I remember on allegro you could do something like this to set TRANSPARENCY on the  fly.


Moru

You can only set transparency before you create the sprite. Either by loading or grabbing. But you can change as often as you like.

Hemlos

Quote from: spudgunjake on 2009-Dec-16
Is it true the getpixel command only gets from the back buffer and not from a virtual screen.

I believe so...however, you can quickly clear the backbuffer with BLACKSCREEN command.
Getpixel is slow as heck, you should avoid this, or use it on just a few pixels.

Bing ChatGpt is pretty smart :O

Kitty Hello

I think GETPIXEL also works on offscreen surfaces.