Open Source JavaFX Now!
Combination View Flat View Tree View
Anchor point of x,y in JavaFX nodes
toggle
Some sprite applications (namely pulpcore) allows you to define an anchor point for an object.

For example if the anchor point of a rectangle is 0,0 and it's coordinates are x:0,y:0 the top left point of the rectangle would be displayed on the top left point of the screen.

If however the anchor point of the rectangle is 50,50 and it's size is 100x100, the middle of the rectangle would be placed at 0,0 and only it's bottom-right part would be displayed.

Is there a similar property in JavaFX? Is there an easy way to implement this (can you bind the x and the y coordinates of a JavaFX node to its own height and width?)?
Flag Flag
RE: Anchor point of x,y in JavaFX nodes
9/5/09 12:46 AM as a reply to Elazar Leibovich.
You can do this, using translateX/Y:

 1var r: Rectangle = Rectangle {
 2  layoutX: 0;
 3  layoutY: 0;
 4  translateX: bind - (r.width - 50) 
 5  translateY: bind - (r.height - 50)
 6  height: 100
 7  width: 100
 8  stroke: Color.BLACK
 9  fill: Color.YELLOW
10  };


so the rectangle would notionally act as though the locationX and Y values were set at the centre of the rectangle for pathing etc. All collision detection etc. should be unaffected.
Flag Flag
RE: Anchor point of x,y in JavaFX nodes
9/8/09 3:41 PM as a reply to Elazar Leibovich.
By default the anchor point is the center of the bounds of your node. That's if you are using the translateX, scaleX, rotate, etc. vars. However, you can use the transforms var to use your own anchor point. For example, if you wanted to rotate your node 90 degrees about the point 10,20, then you'd do this:

Rectangle {
transforms: [Transform.rotate(90,10,20) ]
...
Flag Flag