Hello.
I have created simple Node subclass that contains Box and Text3D and try to resize it at runtime using code:
InputAction plusAction = new InputAction() {
public
void performAction(InputActionEvent evt) {
node.scale(1.2f);
}
};
It scales just one time and then node remains unchanged. What is wrong ?
Thanks.
Im guessing it only scales once because the scale parameters doesnt change, eg. 1.2f…
It wont scale 1.2 times the new scale.
Ie, this doesnt happen:
x unit = 100
scale 1.2f
x unit = 120
scale 1.2f
x unit = 144
Instead this happens:
x unit = 100
scale 1.2f
x unit = 120
scale 1.2f
x unit = 120
scale 1.0f
x unit = 100
Im sure I could have summed that up in less words but you get the point.
I know at least with 2D graphics, it's easier and quicker to scale the original a certain amount, rather than scaling something you've scaled previously (serious performance issues with Java and 2D graphics with this, as well as some weird results…try it!).
Personally, I'd recommend creating a scaling method that will do the math for you to set the new scale value based on what is provided in the method arguments and the previous value (unless you're cool with writing the same code over and over, which bothers me, even if it is something so small).
Something simple like
public static void scaleNode(Node theNode, float value)
{
theNode.scale( value * theNode.getScale() );
}