I am new to quick sprite pack. In the application, I try to make me a submarine moving across the ocean. Each time the user clicks on the screen, gravity begins to pull the sub in the opposite direction. My problem is that I cannot find a way to keep the unit from exiting the screen. I tried to solve this problem by making a physical panel around the screen, but the sub-channel is still coming out of the screen. I also tried the following code in the updateCurrentTime foundation.
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
self.physicsWorld.gravity = CGVectorMake(0,gravity)
if (sub.position.y >= self.size.height - sub.size.height / 2){
sub.position.y = self.size.height - self.sub.size.height / 2
}
if (sub.position.y <= sub.size.height / 2) {
sub.position.y = self.sub.size.height / 2
}
}
But that also doesn’t.
Any help would be greatly appreciated !!!!! thanks in advance! PS I can’t believe that it’s very difficult to keep things on the screen! frustrating!
source
share