How to add a transparent gif sprite in pygame - pygame

I'd like to add a transparent gif sprite in pygame? Any help?
When I add any gif it has a black box around it.

Have you converted the surface using convert_alpha()?
You would usually load an image like so:
sprite_image = pygame.image.load("image.gif").convert_alpha()

Related

How can I draw things in the foreground with pygame?

How can I draw things in the foreground with pygame? With things I mean a text that I draw with .blit. Because I have a floor that hides the text I want to show How could I fix that?
blit draw one image onto another. Therefore you must draw the text after the floor:
screen.blit(floor, floor_pos)
screen.blit(text, text_pos)
First you draw the foreground, then the text.

how check overlapse not transparent fragment object in libgdx

Libgdx.
I have 2 objects: Bucket and drop.
I use Sprite to manipulation on this objects.
How to check overlapse of non-transparent fragment of objects?
I really don't think that there is a function that could handle that.
I use to remove margin that represent the non-transparent of a sprite content
for example if the we put the size of the rectangle that represent the coins like this picture and we ignore the transparent part of the Sprite
good luck !

cocos2d draw something on top of the sprite

I am very new to cocos2d. I have read the basic concept of sprite and action. I was wondering after I created a sprite (from an image file). and I want to draw some numbers on the sprite on the fly, is that something doable? or you can not draw anything on the sprite after creating from an image?
Thanks for your reply in advance.
If you want to display text or numbers over a Sprite, you can add a UIText widget as a child.
auto sprite = Sprite::create("image.png");
addChild(sprite);
auto text = Text::create();
text->setString("Test");
// Position the text in the center of the sprite
text->setPosition(Vec2(sprite->getContentSize().width*.5,
sprite->getContentSize().height*.5));
sprite->addChild(text);
draw sprite using Render Texture and then you can add as a child of the sprite .

Actionscript 3.0 drawRect works weird

I have a BitmapData object named myBitmapData. It was loaded of PNG of size 104x104. This PNG represents a red circle on the transparent background.
There is also a Sprite object named myBackground. I want render that red circle into myBackground.
myBackground.graphics.beginBitmapFill(myBitmapData);
myBackground.graphics.drawRect(0, 0, myBitmapData.width, myBitmapData.height);
myBackground.graphics.endFill();
addChild(myBackground);
Everything is fine. I see a red circle in the left top of myBackground.
But when I change the third line to
myBackground.graphics.drawRect(0, 52, myBitmapData.width, myBitmapData.height);
and expect my circle to be translated 52 pixels down, I actually obtain something strange (for me :)): there are two red half-circles (they form like hourglass).
So, the question is: how do I render myBitmapData into the random position of myBackground?
P.S.
In the case of
myBackground.graphics.drawRect(0, 104, myBitmapData.width, myBitmapData.height);
it is circle again :)
This is caused by beginBitmapFill's default repeat = true parameter. There's an example in the docs. Disabling the repetition won't work though, you'd just get a half circle then.
There are several ways to fix this:
Use a Matrix with a translation (displacement) as argument in beginBitmapFill.
Draw the rectangle at 0,0 on another Sprite, and move that sprite to where you want it on the background.
Don't draw directly to the background, but to another bitmap using copyPixels. Then fill the background with that bitmap.

How do I set a background image in Actionscript?

I have looked around for about two hours now and I can't seem to find the command to convert this little piece of code to change the ball colour to a bitmap:
on(release){
myColor = new Color(_root.ball_mc);
myColor.setRGB(0xFF0000);
}
Assuming your ball is a vector circle, what you can do is use it as the mask on a bitmap object:
http://www.republicofcode.com/tutorials/flash/as3masking/
if it is a circle you're drawing, you can use beginBitmapFill
here is an example