I wish to implement some Frustum Culling in my JavaFX application, as there can be a large amount of Nodes outside the scene but there are some mouse-events such as dragging which may bring them back to the Scene. Is there some method already in the JavaFX framework or would I have to implement this by myself. I have already tried to implement a clipping method which removes the Nodes outside of the Scene however its difficult to update the Scene after mouse events.
Any help would be appreciated
Thanks
Do you require the nodes to be completely removed forever or you worried about rendering?
Nodes outside of the scene should not be rendered at all, this is handled by JavaFX.
My guess is that each node has Listeners attached.. therefore you are creating
(n ->) listeners ...
Perhaps try creating a method that when hovered, add drag listeners / and remove on hover exit.. Also Nodes not rendered on screen should remove such listeners as well.
And maybe wrapping those listeners in the WeakListener classes
just my thoughts...
Related
I want to understand if for example a game object like a SPRITE that if inserted alone represents a scene in godot is related to the concept of OOP object, in practice I want to understand if it is also an OOP object....
In Godot, a node is an object. Not all objects are nodes.
We can see the documentation for Node, that it inherits from Object, where Object is the base class for everything in Godot.
And, of course, Sprite is a Node.
So, all Sprites are Nodes, and all Nodes are Objects.
What is a scene?
First of all, scenes are not C++ classes. I hope this is evident.
Second, there is something called scene inheritance, which suggest scenes are some kind of classes. However, we cannot extend them in code. Scenes are not classes.
Third, we can create Nodes from scene files. If the scene file is not a class, that suggest they are prototypes. But if scenes are prototypes, how do we explain scene inheritance? Well, as it turns out, scenes are not prototypes. It is much simpler than that…
Scenes are Nodes.
As you know, when you tell Godot to add a scene file to the Scene panel you get an item that has a special icon. And - by default - you don't see any children that where in that scene file. This is only they way they are shown in the UI.
Perhaps you wonder how does it look like in memory. Is there a special type of Node for any scene files you add? And the answer is NO. They are regular Nodes.
When you tell Godot to add a scene file to the Scene panel, Godot loads it and instantiate it, getting a Node. Then Godot adds that Node as a child where you told it.
So how does it remember that that Node was added from a scene file?
The Nodes have a filename property that tell us from where it was loaded. So when you are serializing a Node to an scene file, and it has some child Node that has a filename set, instead of serializing that child Node to the same scene file... It is serialized to the file indicated by its filename, and then included by reference.
Of course, the filename property is not visible in the Inspector panel.
But then, what is scene inheritance?
When you have a serialized scene Node (i.e. a scene file), it contains the properties, scripts, children, connections and so on. And as said above, it can include other files by reference.
Scene inheritance is the special case of inclusion where the serialized Node is defined as another scene. That is scene inheritance is extension by inclusion.
Finally there is something called SceneTree. The game will have an SceneTree object (unless you instantiate more), and it references a Node which is considered the current scene.
I am making an adventure game and, in order to go inside buildings, I would have to change scenes. I wanted to ask, since I want to keep the UI when I am entering buildings, how can I swap out a scene that is not the current one?
I am now using the scenemanager that I got from the official Godot documentation to switch scenes, but it doesn't have any functions to swap existing scenes.
I was thinking about placing a main scene within the UI and then another scene which would hold yet another scene. That last scene would be the one switching.
I'm quite new in programming and especially with javafx.
I'm writing a game and i'm trying to visualize at the same time more instances of the same sprite ( a kind of bullet). It translates and rotates.
In my attempts program doesn't work or normally when press 'fire', bullet run but when press 'fire' more times, every time the 'old' bullet' disappear and another bullet starts. Only 1 bullet on the screen at the same time. What have i to do to have more bullets on the screen, exactly one bullet for every time 'fire' is pressed?
Thank you in advance!
You are probably trying to add the same node more than once to the scene graph.
From the JavaFX Node documentation:
A node may occur at most once anywhere in the scene graph. Specifically, a node must appear no more than once in all of the following: as the root node of a Scene, the children ObservableList of a Parent, or as the clip of a Node.
The scene graph must not have cycles. A cycle would exist if a node is an ancestor of itself in the tree, considering the Group content ObservableList, Parent children ObservableList, and Node clip relationships mentioned above.
If a program adds a child node to a Parent (including Group, Region, etc) and that node is already a child of a different Parent or the root of a Scene, the node is automatically (and silently) removed from its former parent. If a program attempts to modify the scene graph in any other way that violates the above rules, an exception is thrown, the modification attempt is ignored and the scene graph is restored to its previous state.
It is possible to rearrange the structure of the scene graph, for example, to move a subtree from one location in the scene graph to another. In order to do this, one would normally remove the subtree from its old location before inserting it at the new location. However, the subtree will be automatically removed as described above if the application doesn't explicitly remove it.
Here is a sample of multiple animated images in a single scene. In the example, multiple nodes are used, each sharing the same Image data. Because Image is not a Node, it can be shared without issue:
How show specific part of an image in javafx
Im trying to figure out if it is possible to run 2scenes concurrently in one stage...
Here's the scenario i have two scenes, and i use borderPane layout; I want to place the first scene at the top of my layout and the other one to the center.
now the question is it possible?
I already consult google and even my other colleague but still stuck with this problem.
Scene is a part of the window inside the Stage. You can't have two of them in one Stage simultaneously.
If you want to have different content on top and center you can use any layout classes, e.g. Pane instead of Scene.
I'm just going through the javadoc and various tutorials on libgdx and I'm at the stage of trying to figure out differences between various concepts that seem similar to me or provide similar capabilities in libgdx.
At first I thought scene2d was about creating interactive items such as menus, etc but various tutorials I'm reading use scene2d/actors for the main game items (i.e. the player, etc) and others just use sprites.
What exactly is the difference between using Sprite and Actor (i.e. scene2D) in a game and when should you choose?
Thanks.
A Sprite is basically an image with a position, size, and rotation. You draw it using SpriteBatch, and once you have your your Sprites and your SpriteBatch, you have a simple, low-level way to get 2D images on the screen anywhere you want. The rest is up to you.
Actor, on the other hand, is part of a scene graph. It's higher-level, and there's a lot more that goes into a scene graph than just positioning images. The root of the scene graph is the Stage, which is not itself displayed. The Stage is a container for the Actors that you add to it, and is used for organizing the scene. In particular, input events are passed down through the Stage to the appropriate Actor, and the Stage knows when to tell the Actor to draw itself. A touch event, for example, only gets sent to the Actor that got touched.
But note that Actor does not contain a texture like Sprite does. Instead you probably want to use Image, a subclass of Actor that's probably closer to Sprite than just a plain Actor. Other subclasses of Actor contain text, and so on.
Another big advantage of Actors is that they can have Actions. These are a big topic, but they essentially allow you to plan a sequence of events for that Actor (like fading in, moving, etc) that will then happen on their own once you set them.
So basically Actor does a lot more than Sprite because it's part of a graphical framework.
It is more or less matter of taste. If you want to use actions and stage, use actors. Actors cannot be drawn directly, you need to override draw method. Inside draw you can use sprites.