本文介绍了具有浮点值的LibGDX乘以Vector2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将Vector2与浮点值相乘?我以前在XNA中这样做是通过将归一化的方向向量乘以速度浮点来计算运动.这几乎是我的代码使工作正常的最后一步,但是似乎没有一个接受float值的Vector2的乘法函数.我可以手动仔细地x和y,但是应该有一个我不知道的方法.

Is there a way to multiply a Vector2 with a float value? I used to do this in XNA to calculate movement by multiplying a normalized direction vector with a velocity float. This pretty much is the last step in my code to make things work but there does not seem a multiply function for a Vector2 that accepts a float value. I could just mulltiply x and y manually but there should be a method for this i don't know about.

推荐答案

来自 http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html :

scl
public Vector2 scl(float x,
                   float y)
Multiplies this vector by a scalar
Returns:
This vector for chaining

所以我想它叫做比例".如果要乘以整个向量,则只需对x和y使用相同的值即可.

So I guess it's called "scale". If you want to multiply the entire vector, just use the same value for x and y.

这篇关于具有浮点值的LibGDX乘以Vector2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 23:11