Reputation: 1037
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: Could someone also explain what scalar multiply is and how it works?
Upvotes: 5
Views: 2766
Reputation: 5012
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.
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);
}
Upvotes: 6