Changing Alpha please help

hi,
In my java3d application i have created a PositionInterpolar that makes a Box move from left to right on the screen at a constant speed. I have also added an KeyListener which increases and decreases the speed of movement by using the up and down arrow keys. I have tested the keylistener and it is working correctly. My problem is that i do not know how to modify the Alpha at runtime to change the speed of movement.

My aplha code -


Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE, 0, 0, speed, 0, 0, speed, 0, 0);

Keylistener code -


public void keyPressed(KeyEvent e)      {           
if (e.getKeyCode() == KeyEvent.VK_UP) {             
speed = speed - 1000;}

The speed value decreases correctly but the Alpha doesnt change speed! Please can anyone help me?

The “speed” parameter passed into the constructor is passed by value, and not by reference. So, when you update the speed value, you also need to update the alpha durations. i.e.

speed = speed - 1000;
transAlpha.setIncreasingAlphaDuration(speed);
transAlpha.setDecreasingAlphaDuration(speed);