Can't add child sprite on scaled object - sprite

Ok, guys, here's the deal.
aboutBackground = Sprite::create("fadeBack.png");
aboutBackground->setScale(winSize.width, winSize.height);
aboutBackground->setPosition(winSize.width*0.5, winSize.height*0.5);
this->addChild(aboutBackground);
Sprite *sprAboutPanel = Sprite::create("aboutPanel.png");
sprAboutPanel->setPosition(aboutBackground->getBoundingBox().size.width*0.5, aboutBackground->getBoundingBox().size.height*0.5);
aboutBackground->addChild(sprAboutPanel);
Before scaling aboutBackground sprite it works perfectly. But because aboutBackground is just a fading background, I decided to go with 1px picture and scale it to full screen. But right now sprAboutPanel doesn't appear on the screen. I really wonder why? Thx for your responses!

One trick you can use in this instance is to not add the about panel as a child of the background, but rather the scene instead. Scaling a parent makes for tricky positioning of children since positions are scaled. You would probably find that in your code if you set the position of aboutPanel to (0.5,0.5) it would probably work as expected.
I would instead change:
aboutBackground->addChild(sprAboutPanel);
to this:
this->addChild(sprAboutPanel);

Related

Can you hide a node when not directly above a parent in Godot?

So I have an instanced scene that is supposed to be the child of a colour rect in my tree. I want to randomly generate the nodes, but I also want parts of the view to be cut off if the texture no longer is above the main section. I know you can render nodes below their parents, but I don't know if stopping part of them from rendering is physically possible.
In this image I want the bottom circle to remain the same, but the top circle to not show anything above the dark purple box
This is the node tree in the editor
Is there any way to do this directly, or am I gonna have to use a viewport of some variety?
I believe what you want is to set rect_clip_content to true on the ColorRect (or whatever Control). Making invisible any part of its children outside of it.
From Godot's documentation:
bool rect_clip_content
Enables whether rendering of CanvasItem based children should be clipped to this control's rectangle. If true, parts of a child which would be visibly outside of this control's rectangle will not be rendered.
If what you want is the opposite, perhaps you can use z_index to have something render on top, occluding the parts you don't want visible.
There is also a trick you can use with lights (including 2D lights):
Make a light that matches the area you want things to be visible.
Set a custom material that will be transparent by default, but visible on the light pass. The simpler way to do this is to set the light_mode of the material to "Light Only". You could also do it with a custom shader instead.
Making something disappear with light, in 2D, is impossible. In 3D, you can use flags_use_shadow_to_opacity. That is how you make a shadow catcher.
But, there is one more trick: you can use a mask. This should give you full control of when to show or hide things. So, if none of the above solutions works for you, use a mask. I have an explanation in a different answer. See also: How to crop sprite in a non-rectangular form?.
Mighty Mochi Games recently (2022-03-30) made a compilation of the different approaches in video form: Mask Methods Collection - Godot 3.x - 2D
.

SpotLight Node Turns Everything Pitch Black

I am a beginner in Godot and I am making a 3D scene. However, when I added a SpotLight node to the scene, all the other objects turned dark. The OmniLight and the DirectionalLight works fine. When I hide the SpotLight, the scene returns to normal. If the SpotLight isn't facing the objects, they remain how it is supposed to be. Any ideas on how to solve this?
Here is what it looks like.
When I make it not visible:
Oh, and these objects are CSG objects, just so you know.
Here is the link to the minimal repro project.

Anyone know if its possible draw to erase the picture on the top?

Scratch allows selection of the color using the set pen color. Does anyone know if its possible to program to set the color to transparent so that what ever is drawn can effectively be erased? What would the color number be for that?
Update
The idea was to cover a picture (background) with a colour drawn over the top. Now give the player a little creature that erases the colour on top, they have a certain amount of moves or time to guess what the picture is. The less moves/time they use the more points the player will be awarded.
But the problem seems to be that in the paint a sprite part of scratch erase is an option, but not in the pen programming.
If I cant solve it using erase apprach, my alternative is to make a lot of sprites covering the picture and hide them when the creature touches them. But it seems less fun for the player as the uncovered patterns will be more predictable.
Unfortunately, this isn't really possible. If you have a backdrop that's all one color, you could set the pen color to be the same as the backdrop and color over what you already have (giving the illusion of erasing), but other than that there really isn't a good way.
Your only other option is to use the clear block and then re-draw everything except the piece you want to erase.
If you want to give more context about your specific project, I might be able to help you work out a solution (I've done quite a lot with pen blocks over the years).
Like PullJosh said, it isn't really possible but you can make a sprite called Cover and make it a circle of any color you want. Then, it can clone it's sprite over the sprite you want to hide. Then you can attach a script to the clones:
https://i.stack.imgur.com/S6h4c.png (ctrl + click)

Moving elements on a layout controlled programmatically

My goal is to create something like the arrow from car that indicates the speed of the car. My problem is that I do not know what is the best practice for moving the green arrow. I have an image arrow.png and I guess I need to manipulate with the place that the picture is shown and with the rotation of the image.
Can someone point to me some guidelines ?
My basic idea is to have a relative layout for the background and to have one image view that will change the position, but the part changing position is little unclear to me. And I do not think that is good idea to play with layout params and margins...
I would probably extend ImageView then override your onDraw method and use canvas.rotate() to rotate the arrow depending on your app state.

Transparency problem with gradient - Label in a Panel on a UserControl, ultimately displayed on parent Form

I know this has been asked many times, but not quite the way I'm trying to solve it.
I have Labels in a Panel on a UserControl, and the UserControl goes onto a form.
The Label.BackColor = Transparent.
The panel is from DevExpress, and I've set a gradient background.
Problem: The Labels aren't transparent; they each show as a white solid rectangle around the text. (I presume the white comes from the Panel, as the first of the two gradient colors is White.)
Everything I google about this problem says I need to roll my own Label control and fire off peculiar GDI+ commands, and Invalidate the control, and hook the Paint event and sing a stirring sea shanty and hold one foot above my head and...
Really? Doesn't the Label allow ".BackColor=Transparent" ? Why doesn't that work?
And what's the best way through this?
Somehow it turns out I never tried making the Label backgrounds transparent.
I am not a proud.

Resources