import SwiftUI
import SpriteKit
extension List {
func listBackground(_ color: Color) -> some View {
UITableView.appearance().backgroundColor = UIColor(color)
return self
}
}
struct ContentView: View {
private let myurl = URL(string: "https://tate.gif.jp/img/d01.jpg")
var body: some View {
NavigationView {
List {
Image("c03")
.resizable()
.aspectRatio(contentMode: .fill)
// .frame(maxWidth: .infinity, maxHeight: 40)
.frame(maxWidth: 40, maxHeight: 40)
.clipped()
HStack {
Circle()
.frame(width: 40, height: 40)
.foregroundColor(.green)
Text("mytitle")
}
NavigationLink(destination: GameA()) {
HStack() {
// Image("c03")
AsyncImage(url: myurl, scale: 7.2)
// .resizable()
.scaledToFill()
.frame(maxWidth: 40, maxHeight: 40)
.clipped()
.cornerRadius(4)
// Spacer(minLength: 1)
.padding(.trailing, 50)
Text("画像とテキストを表示")
}
} .listRowBackground(Color.orange)
NavigationLink(destination: SKContentView()) {
Text("Game").foregroundColor(.blue)
.fontWeight(.black)
}
.listRowBackground(Color.yellow)
NavigationLink(destination: Game2()) {
(Text("G") + Text("a")
.foregroundColor(Color.red)
.fontWeight(.black) + Text("me2"))
}
NavigationLink(destination: Game3()) {
Text("Game3")
.font(.custom("Times-Roman", size: 25))
}
.listRowBackground(Color.red)
NavigationLink(destination: Game4()) {
Text("Game4")
.font(.system(size: 20, weight: .black, design: .default))
}
// .listRowBackground(Color.clear)
.listRowBackground(Color(red: 0.1, green: 0.9, blue: 0.1, opacity: 0.6))
}.listBackground(.blue)
.listStyle(InsetListStyle())
// .navigationTitle("Game a player")
}
}
}
struct Game: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var scene: SKScene {
let scene = GameScene()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
}
struct Game2: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var scene: SKScene {
let scene = GameScene2()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
}
struct Game3: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var scene: SKScene {
let scene = GameScene3()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
}
struct Game4: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var scene: SKScene {
let scene = GameScene4()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
}
struct GameA: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var scene: SKScene {
let scene = GameSceneA()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
}
struct GameB: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var scene: SKScene {
let scene = GameSceneB()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
///////////////////
GameScene
import SwiftUI
import SpriteKit
class GameScene: SKScene {
override func didMove(to view: SKView) {
backgroundColor = .yellow
let TitleLabel = SKLabelNode(fontNamed: "Verdana-bold")
TitleLabel.text = "GameScene"
TitleLabel.fontSize = 30
TitleLabel.horizontalAlignmentMode = .center
TitleLabel.fontColor = SKColor.black
TitleLabel.position = CGPoint(x:175, y:370)
self.addChild(TitleLabel)
}
override func touchesMoved(_ touches: Set, with event: UIEvent?) {
}
}
struct SKContentView: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
@Environment(\.dismiss) var dismiss
var name: String = "Hello SwiftUI!"
var scene: SKScene {
let scene = GameScene()
scene.size = CGSize(width: screenWidth, height: screenHeight)
scene.scaleMode = .fill
return scene
}
var body: some View {
ZStack {
Color.blue
.ignoresSafeArea()
VStack {
SpriteView(scene: scene)
.frame(width: screenWidth, height: screenHeight)
.ignoresSafeArea()
}
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(
action: {
dismiss()
}, label: {
Image(systemName: "arrow.backward")
Text("戻る")
}
).tint(.blue)
}
}
}
}
}
struct SKContentView_Previews: PreviewProvider {
static var previews: some View {
SKContentView()
}
///////////////////////
GameScene3
class GameScene3: SKScene {
let NextLabel = SKLabelNode(fontNamed: "Verdana-bold")
override func didMove(to view: SKView) {
backgroundColor = .red
let TitleLabel = SKLabelNode(fontNamed: "Verdana-bold")
TitleLabel.text = "GameScene3"
TitleLabel.fontSize = 30
TitleLabel.horizontalAlignmentMode = .center
TitleLabel.fontColor = SKColor.black
TitleLabel.position = CGPoint(x:175, y:370)
self.addChild(TitleLabel)
NextLabel.text = "SceneA-bへGO"
NextLabel.fontSize = 30
NextLabel.horizontalAlignmentMode = .center
NextLabel.fontColor = SKColor.black
NextLabel.position = CGPoint(x:175, y:570)
self.addChild(NextLabel)
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
let breakOutGameScene = GameScene4(size: self.size)
self.view?.presentScene(breakOutGameScene)
}
}
//////////////////////
GameScene4
import SwiftUI
import SpriteKit
class GameScene4: SKScene {
override func didMove(to view: SKView) {
backgroundColor = .green
let TitleLabel = SKLabelNode(fontNamed: "Verdana-bold")
TitleLabel.text = "GameSceneAへ"
TitleLabel.fontSize = 30
TitleLabel.horizontalAlignmentMode = .center
TitleLabel.fontColor = SKColor.black
TitleLabel.position = CGPoint(x:175, y:370)
TitleLabel.name = "tail"
self.addChild(TitleLabel)
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
let touchedNode = atPoint(location)
if touchedNode.name == "tail" {
// let reveal = SKTransition.doorway(withDuration: 1)
let scene = GameSceneA(size: self.size)
let skView = self.view!
scene.scaleMode = SKSceneScaleMode.aspectFit
// skView.presentScene(scene, transition: reveal)
skView.presentScene(scene)
}
}
}
}
//////////////////////////////////////
GameSceneA
import SpriteKit
import GameplayKit
class GameSceneA: SKScene {
//各種ラベルの準備
let countLabel = SKLabelNode(fontNamed: "Verdana-bold")
let TitleLabel = SKLabelNode(fontNamed: "Verdana-bold")
let NextLabel = SKLabelNode(fontNamed: "Verdana-bold")
override func didMove(to view: SKView) {
self.backgroundColor = UIColor.cyan
TitleLabel.text = "タイトルA"
TitleLabel.fontSize = 30
TitleLabel.horizontalAlignmentMode = .center
TitleLabel.fontColor = SKColor.black
TitleLabel.position = CGPoint(x:175, y:670)
self.addChild(TitleLabel)
NextLabel.text = "GameSceneBへGO"
NextLabel.fontSize = 30
NextLabel.horizontalAlignmentMode = .center
NextLabel.fontColor = SKColor.black
NextLabel.position = CGPoint(x:175, y:470)
NextLabel.name = "label"
self.addChild(NextLabel)
// countLabel.text = "タップは\(appDelegate.count)回"
countLabel.fontSize = 40
countLabel.horizontalAlignmentMode = .center
countLabel.fontColor = SKColor.black
countLabel.position = CGPoint(x:175, y:70)
self.addChild(countLabel)
}
func touchDown(atPoint pos : CGPoint) {
}
func touchMoved(toPoint pos : CGPoint) {
}
func touchUp(atPoint pos : CGPoint) {
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
let touchedNode = atPoint(location)
if touchedNode.name == "label" {
// let reveal = SKTransition.doorway(withDuration: 1)
let scene = GameSceneB(size: self.size)
let skView = self.view!
scene.scaleMode = SKSceneScaleMode.aspectFit
// skView.presentScene(scene, transition: reveal)
skView.presentScene(scene)
}
}
}
override func touchesMoved(_ touches: Set, with event: UIEvent?) {
}
override func touchesEnded(_ touches: Set, with event: UIEvent?) {
}
override func touchesCancelled(_ touches: Set, with event: UIEvent?) {
}
override func update(_ currentTime: TimeInterval) {
}
}
//////////////////////