SHARE
TWEET

Untitled

a guest Jul 16th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  GameScene.swift
  3. //  HappyBird
  4. //
  5. //  Created by user on 2019/7/16.
  6. //  Copyright © 2019 IDK. All rights reserved.
  7. //
  8.  
  9. import SpriteKit
  10. import GameplayKit
  11.  
  12. class GameScene: SKScene {
  13.    
  14.     private var label : SKLabelNode?
  15.     private var spinnyNode : SKShapeNode?
  16.    
  17.     var background = SKSpriteNode(imageNamed: "background")
  18.    
  19.     override func didMove(to view: SKView) {
  20.        
  21.         // Get label node from scene and store it for use later
  22.         self.label = self.childNode(withName: "//helloLabel") as? SKLabelNode
  23.         if let label = self.label {
  24.             label.alpha = 0.0
  25.             label.run(SKAction.fadeIn(withDuration: 2.0))
  26.         }
  27.        
  28.         // Create shape node to use during mouse interaction
  29.         let w = (self.size.width + self.size.height) * 0.05
  30.         self.spinnyNode = SKShapeNode.init(rectOf: CGSize.init(width: w, height: w), cornerRadius: w * 0.3)
  31.        
  32.         if let spinnyNode = self.spinnyNode {
  33.             spinnyNode.lineWidth = 2.5
  34.            
  35.             spinnyNode.run(SKAction.repeatForever(SKAction.rotate(byAngle: CGFloat(Double.pi), duration: 1)))
  36.             spinnyNode.run(SKAction.sequence([SKAction.wait(forDuration: 0.5),
  37.                                               SKAction.fadeOut(withDuration: 0.5),
  38.                                               SKAction.removeFromParent()]))
  39.         }
  40.        
  41.         addChild(background)
  42.         background.anchorPoint = CGPoint(x: 0, y: 0)
  43.         background.position = CGPoint(x: 100, y : 0)
  44.     }
  45.    
  46.    
  47.     func touchDown(atPoint pos : CGPoint) {
  48.         if let n = self.spinnyNode?.copy() as! SKShapeNode? {
  49.             n.position = pos
  50.             n.strokeColor = SKColor.green
  51.             self.addChild(n)
  52.         }
  53.     }
  54.    
  55.     func touchMoved(toPoint pos : CGPoint) {
  56.         if let n = self.spinnyNode?.copy() as! SKShapeNode? {
  57.             n.position = pos
  58.             n.strokeColor = SKColor.blue
  59.             self.addChild(n)
  60.         }
  61.     }
  62.    
  63.     func touchUp(atPoint pos : CGPoint) {
  64.         if let n = self.spinnyNode?.copy() as! SKShapeNode? {
  65.             n.position = pos
  66.             n.strokeColor = SKColor.red
  67.             self.addChild(n)
  68.         }
  69.     }
  70.    
  71.     override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  72.         if let label = self.label {
  73.             label.run(SKAction.init(named: "Pulse")!, withKey: "fadeInOut")
  74.         }
  75.        
  76.         for t in touches { self.touchDown(atPoint: t.location(in: self)) }
  77.     }
  78.    
  79.     override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  80.         for t in touches { self.touchMoved(toPoint: t.location(in: self)) }
  81.     }
  82.    
  83.     override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
  84.         for t in touches { self.touchUp(atPoint: t.location(in: self)) }
  85.     }
  86.    
  87.     override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
  88.         for t in touches { self.touchUp(atPoint: t.location(in: self)) }
  89.     }
  90.    
  91.    
  92.     override func update(_ currentTime: TimeInterval) {
  93.         // Called before each frame is rendered
  94.     }
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top