I’m an absolute beginner to this engine and just started to use it for a game I want to create for my bachelor thesis. I’m currently doing all the tutorials and encountered the first problem in the fourth tutorial about the simpleUpdate function.
The third exercise of this tutorial tells me to create a pulsating cube. That’s not difficult, of course, and it works, but ONLY if I don’t use a value lower than 0.8 in the following code snippet:
If I change the 0.8 to a 0.7, for example, the cube starts growing indefinitely, caused by the .getX() values dropping below 0. The console output (.getX() values) looks like the following:
@@MateStrysewske said:
The only difference is that println, actually. I just excluded it because it's not important.
Oh, cool… then it must be running just fine. I wonder what else was excluded that wasn’t important. Seriously, though…
One thing to note: scale() is relative. So if scale ever goes to 0 then it will stay 0 forever. If it ever goes negative then it will stay negative forever. So perhaps when you run at the lower threshold it goes negative once and then stays there.
I guess it’s a nice example but the code is not very robust in the face of large tpf (caused by extremely slow frame rates).
Well, instead of saying “it’s not important”, let’s say it’s completely irrelevant for the functionality of the code. Like I said, it’s the only line that I excluded.
That’s a good answer, thank you! So it seems like the update cycle isn’t called often enough to prevent the value from dropping below 0 and therefore the cube grows indefinitely. Would you suggest to use “setLocalScale” then?
Thank you, that helps a lot. I don’t really understand why scale() behaves like that, but it’s good to know that it does and that I should use other stuff instead.
@@MateStrysewske said:
Thank you, that helps a lot. I don't really understand why scale() behaves like that, but it's good to know that it does and that I should use other stuff instead. :)
If you have something 5 units wide (whatever the current scale) and you call scale(0.5) you’d expect it to be 2.5 units wide. Therefore, for the method to have any meaning, if you call scale(0.5) again then it should end up as 1.25 units wide and so on.
If you call scale(-1) then you invert all axes. scale(), move(), and rotate() are all relative. Convenient, but I rarely ever use them in a real game.