Can you hide a node when not directly above a parent in Godot? - 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
.

Related

android wipe animation when button bar slide up

I'm trying to create slidingup animation in android application to change between two view of layout.
I've tried from this tutorial
but the second screen didn't come like what I want.
I want the second layout to come like a wipe animation, like the following picture at the bottom
Refer this:
https://android.googlesource.com/platform/frameworks/base/+/ab51002847ea3dcdc0ba14eb330ab9ec292a9789/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
In the above code, focus on the animateCollapsePanels method
I was able to implement a similar transition by using a clipping Path. Because I didn't want my transition to rule out the use of Layouts in the clipped view, I implemented the clipping at the Layout level following this answer: Custom Layout that rounds the corners of its content
The clipping is no anti-aliased and you would need to do use instead PorterDuff and XferMode based solutions otherwise, but for a linear wipe animation like you're describing, clipping in the layout will achieve what you want. Basically you're doing a linear reveal whereas the accepted answer I linked does a circular clip.

LWUIT Container Style, importing from resource editor

I'm building a Container using code and now I want to set the Styleusing one UnselectedStyle from the Resource Editor.
I'm doing this because, I don't find the way to add a LinearBackground color and a RoundBorder to my Container. When I put the two properties to the Style, the background color has gone.
So I finally add this Style using the UIManager.getInstance().addThemeProps(String name ThemeFromResource); and later the setUIID(String nameStyle). Is working fine...my Containergets the Style, but the app lose the navigation, the back Commandhas gone.
How can do this? I would like to do with my first way...creating the lineargradient and the border and adding it to the style, but I don't find the way.
I would strongly suggest against doing that.
Border's override other forms of background, round border tries to respect some of them but is REALLY inefficient about that. It effectively draws the background on a mutable image then draws the round border on another mutable image, gets the RGB for both and performs a NOT operation to crop the background into a round image. This (as you might understand) is REALLY expensive in terms of performance, while the image is then cached it is still expensive in the longer term.
You should use image borders which are MUCH faster.

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.

What is the proper way of drawing label in OpenGL Viewport?

I have a multiviewport OpenGL modeler application. It has three different viewports : perspective, front and top. Now I want to paint a label for each viewport and not succeeding in doing it.
What is the best way to print a label for each different perspective?
EDITED : The result
Here is the result of my attempt:
I don't understand why the perspective viewport label got scrambled like that. And, Actually I want to draw it in the upper left corner. How do I accomplished this, because I think it want 3D coordinate... is that right? Here is my code of drawing the label
glColor3f(1,0,0);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glRasterPos2f(0,0);
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen("Perspective"), GL_UNSIGNED_BYTE, "Perspective"); // Draws The Display List Textstrlen(label)
glPopAttrib();
I use the code from here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
thanks
For each viewport switch into a projection that allows you to supply "viewport space" coordinates, disable depth testing (glDisable(GL_DEPTH_TEST)) and depth writes (glDepthMask(GL_FALSE)) and draw the text using one of the methods used to draw text in OpenGL (texture mapped fonts, rendering the full text into a texture drawing that one, draw glyphs as actual geometry).
Along with #datenwolf's excellent answer, I'd add just one bit of advice: rather than drawing the label in the viewport, it's usually easier (and often looks better) to draw the label just outside the viewport. This avoids the label covering anything in the viewport, and makes it easy to get nice, cleanly anti-aliased text (which you can normally do in OpenGL as well, but it's more difficult).
If you decide you need to draw the text inside the viewport anyway, I'll add just one minor detail to what #datenwolf said: since you generally do want your text anti-aliased (even if the rest of the picture isn't) you generally want to draw the label after all the other geometry of the picture itself. If you haven't turned on anti-aliasing otherwise, you generally will want to turn it on for drawing the text.

resize and draggable the group of the SVG element

I am working on a SVG application and now want to let a user resize an object using draggable corners, very much like in SVG-edit (http://svg-edit.googlecode.com/svn/trunk/editor/svg-editor.html).
The functionality should work as follows: The user selects an SVG object, drags it to the main ‘canvas’ and once on the ‘canvas’, four corners on the outside of the object appear, the user can drag on each of the corner points & drag to enlarge the object. The objects will be rectangular in shape and created using paths, not using the SVG ‘rect’ function.
Would anyone have any suggestions as to how this should be implemented?
Thanks in Advance
You could take a look at some existing open source implementations. svg-edit is one which you already mentioned.
To showcase a tool that I developed, I wrote a demo which implements this functionality. This which may serve as a simpler and more restrictive example than svg-edit, as it doesn't do too much other than allow you to draw rects and circles, and rotate/translate/scale them.
I have edited jquery to make rect draggable, recently put them in a g and lost this functionality. The g doesn't contain the position data.
Might be possible to bubble down to the children elements.

Resources