问题描述
我正在SpriteKit中构建一个平台游戏,并打算为我的实体实现更新功能,以便它们根据重力和速度移动.但是,我需要使速度增加量与增量时间成比例,以防止帧速率影响实体的移动方式,因此我将导入GLKit以便可以使用标量函数.但是swift不兼容.还有其他方法可以将标量乘以CGPoint或使速度与三角时间成正比?
I am building a platformer game in SpriteKit and was going to implement an update function for my entities so they would move according to gravity and their velocity. However, I need to make the amount of velocity added proportional to delta time to prevent frame rate from affecting how my entities move, so I was going to import GLKit so I could use the scalar functions. However swift is not compatible. Is there some other way of implementing scalar multiply to CGPoints or making velocity propositional to delta time?
PS:有人还能解释标量乘法是什么以及它是如何工作的吗?
PS: Could someone also explain what scalar multiply is and how it works?
推荐答案
当前没有使用CGPoint
进行数学运算的内置方法.有许多第三方库可以执行此操作,这些库大多是在GLKit
之前的版本中构建的.正如您提到的,现在最好的方法是使用GLKit
,它支持Swift.希望很快.
There is currently no built-in way of doing math with CGPoint
s. There are many third party libraries that do this, mostly built in the pre-GLKit
days. As you mentioned, the best way of doing this now is with GLKit
, when it supports Swift. Hopefully soon.
标量乘法非常简单.您只需将CGPoint
的每个分量乘以相同的数字(也称为标量).
Scalar multiplication is super easy. You just need to multiply each component of the CGPoint
with the same number (also called scalars).
CGPoint CGPointMultiplyScalar(CGPoint point, CGFloat scalar) {
return CGPointMake(point.x * scalar, point.y * scalar);
}
这篇关于CGPoint标量乘法Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!