Skip to main content

Adding Groups to Scene during Runtime and Question about pivot points

3 replies [Last post]
emccrckn
Offline
Joined: 2008-08-30
Points: 0

I've used j3d in which nodes can be added/detached to and from branchgroups during runtime with a capability set. Is the same thing possible in javaFX to add/remove nodes to groups or to add/remove groups to and from the scene during Runtime?

Also an unrelated issue:

I'me trying to scale a node around the pivot point of the midpoint in a scene however the node can be translated freely based on mousedrag. Here is the code to get the pivot point:

var point = target.sceneToLocal(stageWidth / 2, stageHeight / 2);
var pivotX = point.x;
var pivotY = point.y;

and then of course:

target.transforms[1] = Transform.scale(scaleX, scaleY,
pivotX, pivotY);

Now I know I have the correct index for the .transforms[i] but I get strange behavior. As long as I have not translated the node yet I can scale the node perfectly. But after translating the node in some direction I get vary odd pivot points. If I zoom in my points tend to oscillate between two points then converge to a point that is usaully offscreen. When zooming out the same activity occurs except the points diverge until the node is offscreen. Any thoughts on what I'm doing wrong? Or maybe a possible bug?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
emccrckn
Offline
Joined: 2008-08-30
Points: 0

Ahhh I see thanks for the info and example

alexsch
Offline
Joined: 2007-07-12
Points: 0

> I've used j3d in which nodes can be added/detached to
> and from branchgroups during runtime with a
> capability set. Is the same thing possible in javaFX
> to add/remove nodes to groups or to add/remove
> groups to and from the scene during Runtime?

For example:

[code]
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.effect.Reflection;

var nodes:Node[] = [

Rectangle {
width: 200,
height: 200
fill: Color.LIGHTGREEN
onMouseClicked: function(e) {

def circle:Circle = Circle{
centerX: e.x
centerY: e.y
radius: 8
fill: Color.BLUE
stroke: Color.BLUE
effect: Reflection{}
blocksMouse: true
onMouseClicked: function( e ) {
delete circle from nodes;
}
};
insert circle into nodes;
}
}
];

Scene {
content: bind nodes
}
[/code]

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Q1: Yes, it is possible to change the scene during runtime. There are no limitations I know of.

Q2: My guess is, that the index in target.transforms[1] is not correct anymore after applying the translation.