# Beginners' Tutorial 4 (Hello Loop) - Excercise 3

Hi, i know this is really basic stuff but i’m quite new to programming, and i just started with jME3.

So i started reading the tutorials and when i got to the end of “Hello Loop” i tried out the excercises. As i couldn’t figure out the third (to make a box pulsate) i looked up the “solutions”, and i found out the given solution was wrong. I mean it doesn’t do what is suppous to do. So i tried to figure it out, and after a lot head scratching i came across these functions on the javadoc: getLocalScale() and getX(). So i made this:

(being t a global int var)

[java]

if (player.getLocalScale().getX() <= 1){

t=1;

} else if (player.getLocalScale().getX() > 1.2) {

t=2;

}

if (t==1) {

player.scale(1+0.0005f);

} else {

player.scale(1-0.0005f);

}

[/java]

And it works just fine, it pulsates and everything. Now my question is:

Is there a reason of why the given solution should use a timer and not just check the object scale?

Salutes

The speed at which a game runs is often quite unstable, so at one given moment, your game could run at 60 fps, and at an other moment the game can run at 120 fps. If you just check the scale every time, then the box will pulsate faster when the game runs faster and slower when the game runs slower. Thus too make it always run at the same speed, you need to keep track of time (Which can be done easily by scaling with something*tpf).

Time is used instead because checking the actual scale has to be done for all three axes: x,y,z. Of course this is up to you on how you implement it, and often all of the 3 scales are the same. But if they are not, you have to take that into consideration. And the solution there just used time to produce the growing effect.

Hope that helps a bit.

@beniboy

Oh, i see! So, i just have to do: player.scale(1+tpf); instead of player.scale(1+0.0005f); Thanks!

@Sploreg

I figured that as i would modify all three axes just checking one would be sufficient.

I first tried to check against a Vector3f but couldn’t figure out the syntax.

Thanks a lot for the replays.