• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Spritekit

My WordPress site

  • Top
  • SpriteKitBase
    • Collision
    • Enumerated
    • Shooting
    • Breakout
    • Physics1
      • physics4
      • physics3
      • Physics2
  • SwiftUI&SpriteKit
    • TabScroll
    • LocalWebView
      • Counter
      • StateObject
      • Button
      • SceneMove
    • Swift Learning
  • Photo Gallery
    • Photo Galler 2
    • Photo Gallery 3
    • リンク
      • プロフィール
      • p5.play test

TappedNodes

08/28/2022 by kyougif


import SpriteKit
import GameplayKit


class GameScene: SKScene {
  let label = SKLabelNode(fontNamed: "HelveticaNeue-Light")
  let button = SKSpriteNode(imageNamed: "blue2.png")
  let button2 = SKLabelNode(text: "Button")
 var n = 0
 let label2 = SKLabelNode(text: "kaisu: 0kai")  

override func didMove(to view: SKView) {
 physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
 self.backgroundColor = .green
    label.text = "Hello World!"
    label.position = CGPoint(x: self.frame.midX, y: self.frame.midY + 10)
    label.fontSize = 20
    label.fontColor = SKColor.white
    self.addChild(label)   

  let labelSize: CGFloat = 30.0
  label2.fontSize = labelSize
  label2.fontName = "Avenir-Black"
  label2.position = CGPoint(x:self.frame.midX, y: 200)
  label2.fontColor = SKColor.black
  self.addChild(label2)

button.position = CGPoint(x: size.width/2, y: size.height/2+120)
button.zPosition = 1
button.name = "button"
 button.setScale(0.4)
 self.addChild(button)
 button.run(SKAction.scale(to: 0.5, duration: 0.3))
 button.alpha = 1

   button2.fontName = "HelveticaNeue-Bold"
  let labelSize2: CGFloat = 30.0
  button2.fontSize = labelSize2
  button2.position = CGPoint(x:self.frame.midX, y:250)
   self.addChild(button2)
   button2.name = "button2"
   button2.color = .blue
    }
override func touchesEnded(_ touches: Set, with event: UIEvent?) {
        button.alpha = 1
        button.setScale(0.5)
    }
 override func touchesMoved(_ touches: Set, with event: UIEvent?) {
    guard let touch = touches.first else { return }
    let toucLocation = touch.location(in: self)
     button2.position.x = toucLocation.x
 }
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
    guard let touch = touches.first else { return }
    let location = touch.location(in: self)
   let tappedNodes = nodes(at: location)
     for node in tappedNodes {
        if node.name == "button" {
           button.alpha = 0.5
           button.setScale(0.6)
           if label.fontSize < 50 {
           label.fontSize += 2
      }
      else{ label.fontSize = 20
   }
 } else if node.name == "button2" {
     button2.fontSize += 1
      n += 1
      label2.text = "kaisu: \(n)kai"
   if button2.fontSize >= 50{
     button2.fontSize = 30
    }
 }
 }
 }
}

Filed Under: Programming, spritekit

Primary Sidebar

最近の投稿

  • ObservableObj
  • SideMenu
  • TabScroll
  • Text
  • TappedNodes
  • Collision2
  • CoreMotion
  • Collision
  • Timer
  • Enumerated
  • Random
  • SwiftUI-List
  • Shooting
  • Sound
  • Camera
  • SpriteSheet
  • SKPhysics42
  • physics4
  • physics3
  • Physics2

アーカイブ

  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2014年9月
  • 2014年5月

カテゴリー

  • Programming
  • spritekit
  • swiftui

固定ページ

  • Home
  • p5.play test
  • Photo Galler 2
  • Photo Gallery
  • Photo Gallery 3
  • Top
  • プロフィール
  • リンク

Copyright © 2026 · Genesis-child on Genesis Framework · WordPress · Log in