Tuesday, 15 May 2012

ios - Locking scene to a sprite node swift xcode -


Basically, I want to move the character (player) and want to follow the "camera" or the scene in the world. The problem is that a camera node is not created in Apple / Xcode, and if I try to move the scene, then I get an error saying something under the influence of "SKScene". I just do not want to take the background and lock the player around in the place because I want to be able to implement the forces for the player node. I went to the website of Apple's Advanced Sean Processing page and followed the example but it does not work. I should cover with a nudge in the right direction!

code:

(I have removed the pieces of code that are irrelevant)

  class PlayScene: on SKScene cannonRotation = 0.0 bridesmaid remove = false override function didMoveToView (see: SKView) allow {physicsWorld.contactDelegate = self self.anchorPoint = CGPoint (X :, SKPhysicsContactDelegate {world = SKNode () player = SKShapeNode (25 circleOfRadius) 0.5, y : 0.5) self.addChild (world) // adds background to the world // adds the elements of visual player.fillColor = UIColor.whiteColor () player.position = CGPoint (X: CGRectGetMidX (self.frame), Y: CGRectGetMinY (self.frame) + 65 + 25) play er.zPosition = 2 player.physicsBody = SKPhysicsBody (circleOfRadius ?? 25) player.physicsBody .dynamic = true player.physicsBody .restitution = 0.9 player.physicsBody .categoryBitMask = BodyType.player.rawValue // Adds GameScene physicsGround let physics properties = SKPhysicsBody (edgeFromPoint: CGPoint (X: CGRectGetMinX (self.frame), Y: CGRectGetMinY (self.frame) +65), Topoint: CGPoint (X: CGRectGetMaxX (self.frame), Y: CGRectGetMinY (self.frame) + 65)) Self {powerlevel () totalPower = powerReached * playCannon.powerMultiplier self.addChild player.physicsBody .applyImpulse (CGVector (dx? Function touchesEnded (: NSSet, withEvent event UIEvent touches): .physicsBody = physicsGround} override CGFloat (float (TotalPower) * Cosf (float (cannonRotation))), sub: CGFloat (float (TotalPower) * Sinf (float (cannonRotation)) ))) fired = true}  

override Kiasimlet Feksiks, and in that function Call

  self.centerOnNode (player);  

What this does, it calls a function that we will create later and it will send parameters of an escondition and in your case this is the player node. centerOnNee Create a method called to add the following parameters

  func centerOnNode (node: Skeanod) {} ​​ 

The centerOnNode add the following line function code

  var cameraPosition:.? CGPoint = node.scene .convertPoint (node.position, fromNode: node.parent) cameraPosition .x = 0 to PosX = Nodekparent Kpositionkx to quote = node.parent .position.y node.parent .position = CGPointMake (PosX - cameraPosition.x, proverb - cameraPosition.y) ??  

will it will focus the camera on the node and updates its status. Code changed from here


No comments:

Post a Comment