simpleUpdate Question

I am new to jME and going through the training. I am trying an exercise to have a cube move up and down using simpleUpdate. This is what I have in simpleUpdate.

[java]

public void simpleUpdate(float tpf) {

player.move(0, 2, 0);

player.move(0, -2, 0);

[/java]

If I replace the 2 player.move lines and replace them with player.rotate(0, 2*tpf, 0); the cube rotates just fine. However with player.move the cube does not move. I have also tried player.move(0, 2tpf, 0) followed by player.move(0, -2tpf, 0) and the cube cant be seen (or it moves so fast i dont see it). Any suggestions will be greatly appreciated. Thanks.

SimpleUpdate happens in one frame, so if you move it up 2 then back down 2, it has essentially moved nowhere.

What you want to do is move the player by a “speed” amount, say 2, and multiply that by ‘tpf’ (Time Per Frame). Then you will see it move up the screen at a rate of 2 units per second.

That works thanks. It now goes up OR down. How do I get it to go up AND down repeatedly?

you will want to have the update loop check that once the object has moved up or down to a certain point, to then inverse the speed value (negating it). This will repeat forever, giving you the up and down motion.



If you are doing this to many objects, have a look at Controls, and AbstractControl. It is the proper way to do this sort of thing without cluttering your main game update loop.

1 Like

Cool thanks for the help :).