I have a SKSpriteNode that runs with accelerometer using the following code:
- (zero) process User: Fare date: (NSEInInternewall) ONLINE {SKSprintNode * SHIP = (SKSCRTNode *) [Own child nodeVithname: @ "fielder"]; CMAccelerometer data * Data = self.motionManager.accelerometerData; If (fibes (data.Scillary)> 0.2) {[gameFish.physicsBody applies: CGVectorMake (0, data.acceleration.y)]; }}
It works well, however, the gamefish runs away from the screen. How can I stop it and live on the screen?
Try using a SKConstraint that was designed exactly for this purpose and in iOS8 Introduced:
Just add it to the setup method of the gamefish node, after the physics run, the game engine impedance will apply. You will not need to worry about it, okay?
// Get Screensaver CGSize scr = self.scene.frame.size; // Setup condition barrier SKConstraint * c = [SKConstraint position X: [Lift limit with SKRange limit: 0 upper limit: scr.width] Y: [lift limit with SKRange limit: 0 upper limit: scr.width]] ; GameFish.constraints = @ [c]; // can take an array of constraints
No comments:
Post a Comment