Shababb Karim Shababb Karim - 1 year ago 77
Java Question

Use of LibGDX scale method

I am a beginner working with the LibGDX library. Recently I have stumbled upon

scl(float dt)
method in the
class. My question is, what is it used for? I know that
float dt
stands for delta time, i.e, the time difference between calling
method now to the last call to
method. Why would I need to use
scl(float dt)
method to, suppose, make an object on the screen fall down instead of just changing the y-axis directly?

Answer Source

First of all LibGDX is a framework, not a library... It's more like a set of libraries that you could use for game development and other stuff. When you multiply a 2D vector by a scalar you just multiply it's "x" value and it's "y" value for that scalar. For example if <4,2> is a vector and you multiply it for the scalar 3. The resulting vector would be <12, 6>. Even when the method says:

scl(float dt)

That does not mean you only can multiply it by the render delta time. You can multiply any vector by any value you want. And for the last question. Why would you use it? Well, it really depends on the exact problem you are trying to fix or the game you are developing. One posible reason I can think of is if your "velocity vector" (Because Vector2 can be used for velocity, position, etc) is suffering a "scalar acceleration" so every frame you are multiplying this velocity for a scalar and the object will be faster every time. Here's a person who needed this method for something LibGDX Multiply Vector2 with float value. So, you see, if you need it, you'll know it.

Hope this helps.