简体   繁体   English

使用LibGDX缩放方法

[英]Use of LibGDX scale method

I am a beginner working with the LibGDX library. 我是LibGDX库的初学者。 Recently I have stumbled upon scl(float dt) method in the Vector2 class. 最近,我在Vector2类中偶然发现了scl(float dt)方法。 My question is, what is it used for? 我的问题是,它的用途是什么? I know that float dt stands for delta time, ie, the time difference between calling render() method now to the last call to render() method. 我知道float dt代表增量时间,即现在调用render()方法与最后一次调用render()方法之间的时间差。 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? 为什么我需要使用scl(float dt)方法来使屏幕上的对象掉下来,而不是直接改变y轴?

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. 首先,LibGDX是一个框架,而不是一个库...它更像是一组可用于游戏开发和其他内容的库。 When you multiply a 2D vector by a scalar you just multiply it's "x" value and it's "y" value for that scalar. 当将2D向量乘以标量时,只需将其乘以“ x”值,并将其乘以“ y”值即可。 For example if <4,2> is a vector and you multiply it for the scalar 3. The resulting vector would be <12, 6>. 例如,如果<4,2>是一个向量,然后将其乘以标量3。结果向量将是<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. 我可能想到的一个可能原因是,您的“速度矢量”(因为Vector2可以用于速度,位置等)正遭受“标量加速度”,因此,每帧您都将该速度乘以标量,则对象将是每次都更快。 Here's a person who needed this method for something LibGDX Multiply Vector2 with float value . 这是一个需要此方法来将LibGDX乘以float2的Vector2的人 So, you see, if you need it, you'll know it. 因此,您会看到,如果需要,您会知道的。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM