I solved using group:
swift
let zoomInAction = SKAction.scale(to: 0.2, duration: 3)
let moving = SKAction.move(to: CGPoint(x: -255, y: 15), duration: 3)
let group = SKAction.group([moving,zoomInAction])
cam.run(group)
Post
Replies
Boosts
Views
Activity
I don't know how you do this for playgrounds, but that's how you integrate spritekit with swiftUI, you use a spriteView:
swift
// A simple game scene with falling boxes
class GameScene: SKScene {
override func didMove(to view: SKView) {
physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
}
override func touchesBegan(_ touches: SetUITouch, with event: UIEvent?) {
guard let touch = touches.first else { return }
let location = touch.location(in: self)
let box = SKSpriteNode(color: SKColor.red, size: CGSize(width: 50, height: 50))
box.position = location
box.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 50))
addChild(box)
}
}
// A sample SwiftUI creating a GameScene and sizing it
// at 300x400 points
struct ContentView: View {
var scene: SKScene {
let scene = GameScene()
scene.size = CGSize(width: 300, height: 400)
scene.scaleMode = .fill
return scene
}
var body: some View {
SpriteView(scene: scene)
.frame(width: 300, height: 400)
.ignoresSafeArea()
}
}
Hope it helps :)
I'm not sure if I understand your problem, but I think that adding a new page or you duplicate existing pages should work. Anyway you can always take a playgroundbook template (from apple) and modify it.
It's possible! I did it in mine. You'll have to add your .sks in the PrivateResourses folder and you'll have to call it in ChaptersChapter1 (or inside the chapter you want)PagesPlaygroundPage1(or inside the page you want)main:
swift
/*:
Text
Text!
*/
//#-hidden-code
import PlaygroundSupport
import SpriteKit
import BookCore
// Load the SKScene from 'GameScene.sks'
let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 683, height: 1024))
// I called my .sks controller Main1 and the fileNamed is the name of .sks
if let scene = Main1(fileNamed: "Main1") {
// Set the scale mode
scene.scaleMode = .aspectFit
// Present the scene
sceneView.presentScene(scene)
}
PlaygroundSupport.PlaygroundPage.current.liveView = sceneView
//#-end-hidden-code
Hope it helps!
I agree with @aminouled, I already had this problem and I solved It writing a note on the book part of the playground asking the jugdes to Disable Results before running
You can create in the playgrounds app or in the Xcode, i would suggest in Xcode, because playground has more bugs.
You can send it as a .playground or .playgroundbook, they're both accepted.
If you're using author's template, check it out a template that i made, where i used hidden code: https://github.com/dudamello/TemplateWWDC
Hope it helps
I think it doesn't count, but we're never sure. I would try to make the hole experience quicker, if it's possible, and not leaving the best for the end.
You can only add icons in the playground if it's a .playgroundbook
Same problem! Selecting your project and under General-App icons and launch images-Launch Screen File = Main worked for me!
This is how i solved it:
ContentView.swift
import SwiftUI
struct ContentView: View {
		var body: some View {
				SpriteKitContainer(scene: SpriteScene())
		}
}
struct ContentView_Previews: PreviewProvider {
		static var previews: some View {
				ContentView()
		}
}
SpriteKitContainer.swift
import SwiftUI
import SpriteKit
struct SpriteKitContainer: UIViewRepresentable {
		typealias UIViewType = SKView
		
		var skScene: SKScene!
		
		init(scene: SKScene) {
				skScene = scene
				self.skScene.scaleMode = .resizeFill
		}
		
		class Coordinator: NSObject {
				var scene: SKScene?
		}
		
		func makeCoordinator() -> Coordinator {
				let coordinator = Coordinator()
				coordinator.scene = self.skScene
				return coordinator
		}
		
		func makeUIView(context: Context) -> SKView {
				let view = SKView(frame: .zero)
				view.preferredFramesPerSecond = 60
				view.showsFPS = true
				view.showsNodeCount = true
				
				return view
		}
		
		func updateUIView(_ view: SKView, context: Context) {
				view.presentScene(context.coordinator.scene)
		}
}
struct SpriteKitContainer_Previews: PreviewProvider {
		static var previews: some View {
				Text("Hello, World!")
		}
}
SpriteKitScene.swift
import UIKit
import SpriteKit
class SpriteScene: SKScene {
		
		//change the code below to whatever you want to happen on skscene
		
		override func didMove(to view: SKView) {
				physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
		}
		
		override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
				guard let touch = touches.first else { return }
				
				let location = touch.location(in: self)
				let box = SKSpriteNode(color: .red, size: CGSize(width: 50, height: 50))
				box.position = location
				box.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 50))
				addChild(box)
		}
}
PS: you'll only see the spritekitscene working in the simulator, it won't work in the preview
It is possible.
You'll need to create a SpriteKitContainer.swift:
import SwiftUI
import SpriteKit
struct SpriteKitContainer: UIViewRepresentable {
typealias UIViewType = SKView
var skScene: SKScene!
init(scene: SKScene) {
skScene = scene
self.skScene.scaleMode = .resizeFill
}
class Coordinator: NSObject {
var scene: SKScene?
}
func makeCoordinator() -> Coordinator {
let coordinator = Coordinator()
coordinator.scene = self.skScene
return coordinator
}
func makeUIView(context: Context) -> SKView {
let view = SKView(frame: .zero)
view.preferredFramesPerSecond = 60
view.showsFPS = true
view.showsNodeCount = true
return view
}
func updateUIView(_ view: SKView, context: Context) {
view.presentScene(context.coordinator.scene)
}
}
struct SpriteKitContainer_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
}
}
After that, you need to create your skscene that will be something like this:
import UIKit
import SpriteKit
class SpriteScene: SKScene {
/*change the code below to whatever you want to happen on skscene*/
override func didMove(to view: SKView) {
physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let location = touch.location(in: self)
let box = SKSpriteNode(color: .red, size: CGSize(width: 50, height: 50))
box.position = location
box.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 50))
addChild(box)
}
}
And this is how you will call the spritekitscene in your ContentView:
import SwiftUI
struct ContentView: View {
var body: some View {
SpriteKitContainer(scene: SpriteScene())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
PS: you'll only see the spritekitscene working in the simulator, it won't work in the preview