I am working on a game like doodle jump.
But when the player jumps above the screen, the player should stay at the edge of the screen and instead the objects will move downwards so it looks like the player i still moving upwards.
But how do I do this?
This is what I tried:
if player.position.y > -0.35 * frame2.size.height{
grond.physicsBody?.applyImpulse(CGVectorMake(0, -player.physicsBody?.velocity.dy))
player.position.y = -0.35 * frame2.size.height
}
But this gives error: operand of postfix ! should have optional type, type is CGFloat.
CGVectorMake
takes two CGFloats. Optional chaining will yield the same type, but wrapped in an optional so you need to unwrap it :
CGVectorMake(0, (-player.physicsBody?.velocity.dy)!))