Update image of SCNNode - ios

if (wallFrame == nil) {
wallFrame = WallFrame()
wallFrame.name = "Image"
}
wallFrame.transform = SCNMatrix4((horizontalHit.anchor!.transform))
wallFrame.eulerAngles = SCNVector3Make(wallFrame.eulerAngles.x + (Float.pi / 2), wallFrame.eulerAngles.y, wallFrame.eulerAngles.z)
let positionz = SCNVector3Make(horizontalHit.worldTransform.columns.3.x, horizontalHit.worldTransform.columns.3.y, horizontalHit.worldTransform.columns.3.z)
wallFrame.position = positionz
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
let image = UIImage(named: "deer.png")
elf.wallFrame.geometry?.firstMaterial?.diffuse.contents = image
}
arView.scene.rootNode.addChildNode(wallFrame)
I am creating a Custom SCNNode and trying to update the image content but it is not updating. How can I update SCNnode?

Related

Xcode- Image View Not Changing

I am trying to update a UIImageView using a for loop, however, the image only shows up on the last iteration of the loop. The code is intended to display a QR code, wait 4 seconds, then display a different QR code, however it only shows the last QR code.
for record in 1...importedrecords.count-3 {
let qrCode = importedrecords[record][0] + " " + importedrecords[record][1] + " " + importedrecords[record][7]
print("QR Code is: " + qrCode)
let data = qrCode.data(using: .ascii, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(data, forKey: "InputMessage")
let ciImage = filter?.outputImage
let transform = CGAffineTransform(scaleX: 10, y: 10)
let transformImage = ciImage?.transformed(by: transform)
let image = UIImage(ciImage: transformImage!)
self.myImageView.image = image
do {
sleep(4)
}
}
I suggest to use Timer for this. Using sleep is not recommended, especially on the main thread, since it stops all the work being done on the thread.
var timer: Timer?
var recordIndex = 0
var importedRecords = [[String]]()
// Call this when you want to start updating
func startUpdate() {
timer = Timer.scheduledTimer(timeInterval: 4, target: self, selector:#selector(updateQR), userInfo: nil, repeats: true)
}
// Call this when you want to stop and reset updating
func stopUpdate() {
timer?.invalidate()
recordIndex = 0
}
#objc
func updateQR() {
let qrCode = importedRecords[recordIndex][0] + " " + importedRecords[recordIndex][1] + " " + importedRecords[recordIndex][7]
print("QR Code is: " + qrCode)
let data = qrCode.data(using: .ascii, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(data, forKey: "InputMessage")
let ciImage = filter?.outputImage
let transform = CGAffineTransform(scaleX: 10, y: 10)
let transformImage = ciImage?.transformed(by: transform)
let image = UIImage(ciImage: transformImage!)
myImageView.image = image
// This will prevent out of bounds crash
if recordIndex < importedRecords.count {
recordIndex += 1
} else {
stopUpdate()
}
}

ARKit not working as expected, If the surface is plain, like a one-colored wall, it’s not detected

I am working on one application which has one functionality like user needs to show the paintings(in 2D images) on the surface with ARKit.
I have implemented it but it has some issues.
It works only for the surfaces that have distinguishable features — e.g. hanging photos, text or art. If the surface is plain, like a one-colored wall, or has only a few small features, it’s not detected. Which means that most of the walls are invisible to ARKit.
Need some solution for this. Any help would be appreciated.
{
self.node.removeFromParentNode()
node.eulerAngles.z = 0
//node.scale = SCNVector3(1.0, 1.0, 1.0)
self.viewAR.backgroundColor = UIColor.clear
self.imageView.contentMode = .scaleAspectFit
self.viewAR.frame = CGRect(x: 0.0, y: 0.0, width: 250, height: 250)
self.imageView.frame = self.viewAR.frame
self.node.geometry = SCNPlane(width: 0.05, height: 0.05)
if selectedIndexPath.row < 0 {
self.imageView.layer.borderColor = UIColor.clear.cgColor
}
else {
self.imageView.layer.borderColor = colors[selectedIndexPath.row].cgColor
}
self.imageView.layer.borderWidth = 10.0
self.viewAR.addSubview(self.imageView)
if let resWidth = self.newWork?.getSetArtWidth, let resHeight = self.newWork?.getSetArtHeight {
if resWidth > 0.0 && resHeight > 0.0 {
self.viewAR.addSubview(self.lblDimension)
self.lblDimension.backgroundColor = colors[selectedIndexPath.row]
self.lblDimension.textColor = UIColor.white
self.lblDimension.text = "Size = \(resWidth) mm * \(resHeight) mm"
}
}
if aRImageList.count != 0 {
if let imgUrl = aRImageList[imageIndex] as? String {
if let resUrl = URL(string: imgUrl){
self.imageView.sd_setImage(with: resUrl, placeholderImage: LISTING_PLACEHOLDER , completed: { (image, error, disk, imageURL) in
if error == nil {
self.imageView.image = image
if let image = image {
self.setImageSize(image)
}
self.node.geometry?.firstMaterial?.isDoubleSided = true
self.node.geometry?.firstMaterial?.diffuse.contents = self.viewAR.asImage()
}
})
} else {
self.imageView.image = LISTING_PLACEHOLDER
}
}
else if let resImage = aRImageList[imageIndex] as? UIImage {
self.imageView.image = resImage
}
//self.imageView.image = aRImageList[imageIndex]
}
node.geometry?.firstMaterial?.diffuse.contents = viewAR.asImage()//aRImageList[imageIndex]//viewToAdd
if isHorizontal == true {
//let resScale = node.scale
// let resAngle = node.eulerAngles.z
node.position = SCNVector3(hitTestResult.worldTransform.columns.3.x, hitTestResult.worldTransform.columns.3.y, hitTestResult.worldTransform.columns.3.z)
//node.scale = resScale
//node.eulerAngles.z = resAngle
node.pivot = SCNMatrix4Rotate(node.pivot, Float.pi, 0, 1, 0)
let constraint = SCNLookAtConstraint(target:sceneView.pointOfView)
constraint.isGimbalLockEnabled = true
node.constraints = [constraint]
}
else {
node.constraints = nil
node.pivot = SCNMatrix4MakeTranslation(0,0,0)
let resScale = node.scale
//let resAngle = node.eulerAngles.z
node.transform = SCNMatrix4(hitTestResult.anchor!.transform)
node.eulerAngles = SCNVector3(node.eulerAngles.x + (-Float.pi / 2), node.eulerAngles.y, node.eulerAngles.z)
node.position = SCNVector3(hitTestResult.worldTransform.columns.3.x, hitTestResult.worldTransform.columns.3.y, hitTestResult.worldTransform.columns.3.z + 0.07)
node.scale = resScale
// node.eulerAngles.z = resAngle
}
sceneView.scene.rootNode.addChildNode(node)
planeNode.removeFromParentNode()
for removeNode in self.planeNodes {
removeNode.removeFromParentNode()
}
}

Dispatch for loading UIImages producing unexpected results

I am building an app that has several images(Plans) that are loaded and setup on a scrollview with a page content. I am trying to load the first image on the main thread and then load the surrounding images from it's index on a background thread. All the UIImageViews are in an array (planImages) to reference when I need to set their images with the loaded data.
The problem is the images aren't always updating with the recently loaded images. This is my first time using Dispatch, so is there something I am doing wrong? Here is the section of code that is giving me the issue.
func setupPagesInScrollView(firstImage: Int)
{
let numberOfPages: CGFloat = CGFloat(selectedDetails!.numberOfPlans)
scrollView!.contentSize = CGSize(width: scrollView!.frame.width * numberOfPages, height: scrollView!.frame.height)
pageControl!.numberOfPages = selectedDetails!.numberOfPlans
if(planImages.count < selectedDetails!.numberOfPlans)
{
for index in planImages.count...selectedDetails!.numberOfPlans - 1
{
let iView = UIImageView()
iView.frame = CGRect(x: 0, y: 0, width: scrollView!.frame.width, height: scrollView!.frame.height)
planImages.append(iView)
scrollView!.addSubview(iView)
iView.translatesAutoresizingMaskIntoConstraints = false
iView.topAnchor.constraint(equalTo: scrollView!.topAnchor).isActive = true
iView.leftAnchor.constraint(equalTo: scrollView!.leftAnchor, constant: scrollView!.frame.width * CGFloat(index)).isActive = true
iView.heightAnchor.constraint(equalToConstant: scrollView!.contentSize.height).isActive = true
iView.widthAnchor.constraint(equalToConstant: scrollView!.frame.width).isActive = true
}
}
DispatchQueue.global(qos: .background).async
{
//Load first selected image
let path = self.selectedDetails!.dirPath + self.selectedDetails!.plansName
self.setupImageAtIndex(path: path, index: firstImage)
//Build Image data around first image on background threads
var mask = 1
let max = self.selectedDetails!.numberOfPlans
while firstImage + mask < max || firstImage - mask > 0
{
if(firstImage + mask < max)
{
self.setupImageAtIndex(path: path, index: firstImage + mask)
}
if(firstImage - mask >= 0)
{
self.setupImageAtIndex(path: path, index: firstImage - mask)
}
mask = mask + 1
}
//Remove extra images from memory if needed
if(self.planImages.count > self.selectedDetails!.numberOfPlans)
{
let dif = self.planImages.count - self.selectedDetails!.numberOfPlans
for _ in 1...dif
{
let index = self.planImages.count - 1
let plan = self.planImages[index]
self.planImages.remove(at: index)
plan.removeFromSuperview()
plan.image = nil
}
}
}
}
private func setupImageAtIndex(path: String, index: Int)
{
let imageName = index + 1 > 9 ? path + String(index + 1) : path + "0" + String(index + 1)
planImages[index].image = UIImage(contentsOfFile: imageName)
}
As per apple documentation You must update UI elements on the main queue.
Update your code like this
private func setupImageAtIndex(path: String, index: Int)
{
let imageName = index + 1 > 9 ? path + String(index + 1) : path + "0" + String(index + 1)
DispatchQueue.main.async {
planImages[index].image = UIImage(contentsOfFile: imageName)
}
}

Why is my screen not rendering anything?

I have the following code. When I run this I am getting a blank screen. This block of code is inside sceneDidLoad() so they will get executed but not displaying anything. Am I missing something ?
let worldNode = SKNode()
let height = 100
let width = 100
let regions:[Float: String] = [-0.04: "sand", -0.08: "water", 0.9: "grass"]
let noiseSource = GKPerlinNoiseSource()
let noise: GKNoise = GKNoise(noiseSource: noiseSource)
let noiseMap: GKNoiseMap = GKNoiseMap(noise: noise)
let tileMapNode = SKTileMapNode()
tileMapNode.enableAutomapping = true
tileMapNode.numberOfRows = height
tileMapNode.numberOfColumns = width
worldNode.addChild(tileMapNode)
for y in 0 ... height {
for x in 0 ... width {
let currentHeight = noiseMap.value(atPosition: vector2(Int32(x), Int32(y)));
for (key, value) in regions {
if (currentHeight <= key) {
//colourMap [y * mapChunkSize + x] = regions[i];
let tileSize = CGSize(width: 32.0, height: 32.0)
let tileTexture = SKTexture(imageNamed: value)
let tileDef = SKTileDefinition(texture: tileTexture, size: tileSize)
let tileGroup = SKTileGroup(tileDefinition: tileDef)
tileMapNode.setTileGroup(tileGroup, forColumn: x, row: y)
print("Tiling: \(value)")
break;
}
}
}
}
self.addChild(worldNode)

ios Swift - Group separated sprites with syncronized animation

I am trying to make a synchronized animation (a large video decomposed by frames on separated and smaller puzzle jigsaw parts). This game is a video puzzle. Here is the code I use in three parts by way of example:
func Anim_Puzzle13 (Node13 : SKPuzzle) {
let puzzle13 = SKAction.animateWithTextures(sheet_puzzle13.Puzzle13_(), timePerFrame: 0.066)
NPuzzle13 = Node13
NPuzzle13.runAction(SKAction.repeatActionForever(puzzle13))
NPuzzle13.position = CGPoint(x: 500, y: 400)
NPuzzle13.zPosition = 1
}
func Anim_Puzzle19 (Node19 : SKPuzzle) {
let puzzle19 = SKAction.animateWithTextures(sheet_puzzle19.Puzzle19_(), timePerFrame: 0.066)
NPuzzle19 = Node19
NPuzzle19.runAction(SKAction.repeatActionForever(puzzle19))
NPuzzle19.position = CGPoint(x: 600, y: 500)
NPuzzle19.zPosition = 1
}
func Anim_Puzzle30 (Node30 : SKPuzzle) {
let puzzle30 = SKAction.animateWithTextures(sheet_puzzle30.Puzzle30_(), timePerFrame: 0.066)
NPuzzle30 = Node30
NPuzzle30.runAction(SKAction.repeatActionForever(puzzle30))
NPuzzle30.position = CGPoint(x: 700, y: 600)
NPuzzle30.zPosition = 1
}
It works well but it does not synchronize between the animations and the video has no integrity. I searched for a long time for a solution to make the animations synchronize; I see two possibilities: first is to create a unique SKNode() with all the jigsaw parts inside, but I want to be able to move each jigsaw part independently and have had no success getting a synchronized animation with this method.
The other way seem to be to create a group with all the animations together but this doesn't work, and causes the application to stop.
Here is all the code I use:
import SpriteKit
import UIKit
import AVFoundation
import AVKit
import CoreFoundation
private let kpuzzleNodeName = "puzzle"
private let kdancing = "dancing"
class SKPuzzle: SKSpriteNode {
var name2:String = "";
}
class GameScene: SKScene {
var background = SKVideoNode(videoFileNamed: "Video_Socle.mov")
var selectedNode = SKPuzzle()
var player:AVPlayer?
var videoNode:SKVideoNode?
var NPuzzle13 = SKPuzzle()
var NPuzzle19 = SKPuzzle()
var NPuzzle30 = SKPuzzle()
var NPuzzle11 = SKPuzzle()
var NPuzzle29 = SKPuzzle()
var NPuzzle35 = SKPuzzle()
var puzzle13 = SKAction()
var puzzle19 = SKAction()
var puzzle30 = SKAction()
var puzzle11 = SKAction()
var puzzle29 = SKAction()
var puzzle35 = SKAction()
let sheet_puzzle13 = Puzzle13()
let sheet_puzzle19 = Puzzle19()
let sheet_puzzle30 = Puzzle30()
let sheet_puzzle11 = Puzzle11()
let sheet_puzzle29 = Puzzle29()
let sheet_puzzle35 = Puzzle35()
override init(size: CGSize) {
super.init(size: size)
// 1
self.background.name = kdancing
self.background.anchorPoint = CGPointZero
background.zPosition = 0
self.addChild(background)
// 2
let sheet = Statiques()
let sprite_dancing1 = SKSpriteNode(texture: sheet.Dancing1())
let sprite_dancing2 = SKSpriteNode(texture: sheet.Dancing2())
sprite_dancing1.name = kdancing
sprite_dancing2.name = kdancing
sprite_dancing1.position = CGPoint(x: 837, y: 752)
sprite_dancing1.zPosition = 2
sprite_dancing2.position = CGPoint(x: 1241, y: 752)
sprite_dancing2.zPosition = 2
background.addChild(sprite_dancing1)
background.addChild(sprite_dancing2)
let imageNames = [sheet.Puzzle13() , sheet.Puzzle19(), sheet.Puzzle30(), sheet.Puzzle11(), sheet.Puzzle29(), sheet.Puzzle35() ]
for i in 0..<imageNames.count {
let imageName = imageNames[i]
let sprite = SKPuzzle(texture: imageName)
sprite.name = kpuzzleNodeName
sprite.name2 = "\(i)"
let offsetFraction = (CGFloat(i) + 1.0)/(CGFloat(imageNames.count) + 1.0)
sprite.position = CGPoint(x: size.width * offsetFraction, y: size.height / 2)
sprite.zPosition = 3
background.addChild(sprite)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let positionInScene = touch.locationInNode(self)
selectNodeForTouch(positionInScene)
}
}
override func didMoveToView(view: SKView) {
let urlStr = NSBundle.mainBundle().pathForResource("Video_Socle", ofType: "mov")
let url = NSURL(fileURLWithPath: urlStr!)
player = AVPlayer(URL: url)
NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayToEndTimeNotification, object: player!.currentItem, queue: nil)
{ notification in
let t1 = CMTimeMake(5, 100);
self.player!.seekToTime(t1)
self.player!.play()
}
videoNode = SKVideoNode(AVPlayer: player!)
videoNode!.position = CGPointMake(frame.size.width/2, frame.size.height/2)
videoNode!.size = CGSize(width: 2048, height: 1536)
videoNode!.zPosition = 0
background.addChild(videoNode!)
videoNode!.play()
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(GameScene.handlePanFrom(_:)))
self.view!.addGestureRecognizer(gestureRecognizer)
}
func handlePanFrom(recognizer : UIPanGestureRecognizer) {
if recognizer.state == .Began {
var touchLocation = recognizer.locationInView(recognizer.view)
touchLocation = self.convertPointFromView(touchLocation)
self.selectNodeForTouch(touchLocation)
} else if recognizer.state == .Changed {
var translation = recognizer.translationInView(recognizer.view!)
translation = CGPoint(x: translation.x, y: -translation.y)
self.panForTranslation(translation)
recognizer.setTranslation(CGPointZero, inView: recognizer.view)
} else if recognizer.state == .Ended {
}
}
func degToRad(degree: Double) -> CGFloat {
return CGFloat(degree / 180.0 * M_PI)
}
func selectNodeForTouch(touchLocation : CGPoint) {
// 1
let touchedNode = self.nodeAtPoint(touchLocation)
if touchedNode is SKPuzzle {
// 2
if !selectedNode.isEqual(touchedNode) {
selectedNode.runAction(SKAction.rotateToAngle(0.0, duration: 0.1))
selectedNode = touchedNode as! SKPuzzle
// 3
if touchedNode.name! == kpuzzleNodeName {
let sequence = SKAction.sequence([SKAction.rotateByAngle(degToRad(-4.0), duration: 0.1),
SKAction.rotateByAngle(0.0, duration: 0.1),
SKAction.rotateByAngle(degToRad(4.0), duration: 0.1)])
selectedNode.runAction(SKAction.repeatActionForever(sequence))
}
}
}
}
func panForTranslation(translation : CGPoint) {
let position = selectedNode.position
if selectedNode.name! == kpuzzleNodeName {
selectedNode.position = CGPoint(x: position.x + translation.x * 2, y: position.y + translation.y * 2)
print (selectedNode.name)
print (selectedNode.name2)
if selectedNode.name2 == "0" {
Anim_Puzzle13(selectedNode)
}
print (selectedNode.name2)
if selectedNode.name2 == "1" {
Anim_Puzzle19(selectedNode)
}
print (selectedNode.name2)
if selectedNode.name2 == "2" {
Anim_Puzzle30(selectedNode)
}
print (selectedNode.name2)
if selectedNode.name2 == "3" {
Anim_Puzzle11(selectedNode)
}
print (selectedNode.name2)
if selectedNode.name2 == "4" {
Anim_Puzzle29(selectedNode)
}
print (selectedNode.name2)
if selectedNode.name2 == "5" {
Anim_Puzzle35(selectedNode)
}
}
}
func Anim_Puzzle13 (Node13 : SKPuzzle) {
let puzzle13 = SKAction.animateWithTextures(sheet_puzzle13.Puzzle13_(), timePerFrame: 0.066)
NPuzzle13 = Node13
NPuzzle13.runAction(SKAction.repeatActionForever(puzzle13))
NPuzzle13.position = CGPoint(x: 500, y: 400)
NPuzzle13.zPosition = 1
}
func Anim_Puzzle19 (Node19 : SKPuzzle) {
let puzzle19 = SKAction.animateWithTextures(sheet_puzzle19.Puzzle19_(), timePerFrame: 0.066)
NPuzzle19 = Node19
NPuzzle19.runAction(SKAction.repeatActionForever(puzzle19))
NPuzzle19.position = CGPoint(x: 600, y: 500)
NPuzzle19.zPosition = 1
}
func Anim_Puzzle30 (Node30 : SKPuzzle) {
let puzzle30 = SKAction.animateWithTextures(sheet_puzzle30.Puzzle30_(), timePerFrame: 0.066)
NPuzzle30 = Node30
NPuzzle30.runAction(SKAction.repeatActionForever(puzzle30))
NPuzzle30.position = CGPoint(x: 700, y: 600)
NPuzzle30.zPosition = 1
}
func Anim_Puzzle11 (Node11 : SKPuzzle) {
let puzzle11 = SKAction.animateWithTextures(sheet_puzzle11.Puzzle11_(), timePerFrame: 0.066)
NPuzzle11 = Node11
NPuzzle11.runAction(SKAction.repeatActionForever(puzzle11))
NPuzzle11.position = CGPoint(x: 800, y: 700)
NPuzzle11.zPosition = 1
}
func Anim_Puzzle29 (Node29 : SKPuzzle) {
let puzzle29 = SKAction.animateWithTextures(sheet_puzzle29.Puzzle29_(), timePerFrame: 0.066)
NPuzzle29 = Node29
NPuzzle29.runAction(SKAction.repeatActionForever(puzzle29))
NPuzzle29.position = CGPoint(x: 900, y: 800)
NPuzzle29.zPosition = 1
}
func Anim_Puzzle35 (Node35 : SKPuzzle) {
let puzzle35 = SKAction.animateWithTextures(sheet_puzzle35.Puzzle35_(), timePerFrame: 0.066)
NPuzzle35 = Node35
NPuzzle35.runAction(SKAction.repeatActionForever(puzzle35))
NPuzzle35.position = CGPoint(x: 1000, y: 900)
NPuzzle35.zPosition = 1
}
}
I'm not sure if it's possible to synchronize animations like this: with SKAction() in several separated parts, because it's necessary to be able to select them individually.
UPDATE: I've tried to follow the action group way but I have the same animation playing on each sprite instead of a different animation synchronized for each sprite (6 different animations synchronized: 6 different sprites):
let sheet13 = Puzzle13()
let sheet19 = Puzzle19()
let sheet30 = Puzzle30()
let sheet11 = Puzzle11()
let sheet29 = Puzzle29()
let sheet35 = Puzzle35()
let imageAnims = [sheet13.Puzzle13_0000() , sheet19.Puzzle19_0000(), sheet30.Puzzle30_0000(), sheet11.Puzzle11_0000(), sheet29.Puzzle29_0000(), sheet35.Puzzle35_0000() ]
let puzzle13 = SKAction.animateWithTextures(sheet13.Puzzle13_(), timePerFrame: 0.066)
let puzzle19 = SKAction.animateWithTextures(sheet19.Puzzle19_(), timePerFrame: 0.066)
let puzzle30 = SKAction.animateWithTextures(sheet30.Puzzle30_(), timePerFrame: 0.066)
let puzzle11 = SKAction.animateWithTextures(sheet11.Puzzle11_(), timePerFrame: 0.066)
let puzzle29 = SKAction.animateWithTextures(sheet29.Puzzle29_(), timePerFrame: 0.066)
let puzzle35 = SKAction.animateWithTextures(sheet35.Puzzle35_(), timePerFrame: 0.066)
let group = SKAction.group([puzzle13,puzzle19,puzzle30,puzzle11,puzzle29,puzzle35])
for i in 0..<imageAnims.count {
let imageAnim = imageAnims[i]
let spriteAnim = SKPuzzle(texture: imageAnim)
spriteAnim.name = kanimNodeName
spriteAnim.name2 = "\(i)"
let offsetFraction = (CGFloat(i) + 1.0)/(CGFloat(imageAnims.count) + 1.0)
spriteAnim.position = CGPoint(x: ((size.width)*2) * offsetFraction, y: size.height * 1.5)
spriteAnim.zPosition = 3
spriteAnim.runAction(SKAction.repeatActionForever(group))
background.addChild(spriteAnim)
}
First of all I want to list two differents method to create your SKAction:
Starting with parallel actions by using SKAction.group:
let sprite = SKSpriteNode(imageNamed:"Spaceship")
let scale = SKAction.scaleTo(0.1, duration: 0.5)
let fade = SKAction.fadeOutWithDuration(0.5)
let group = SKAction.group([scale, fade])
sprite.runAction(group)
Another useful method can be the completion , so you can know when an SKAction was finished:
extension SKNode
{
func runAction( action: SKAction!, withKey: String!, optionalCompletion: dispatch_block_t? )
{
if let completion = optionalCompletion
{
let completionAction = SKAction.runBlock( completion )
let compositeAction = SKAction.sequence([ action, completionAction ])
runAction( compositeAction, withKey: withKey )
}
else
{
runAction( action, withKey: withKey )
}
}
}
Usage:
node.runAction(move,withKey:"swipeMove",optionalCompletion: {
// here the action is finished, do whatever you want
})
After that, about your project, I've seen many node.runAction.., you can also adopt this strategy to sinchronize your actions:
var myAction30 :SKAction!
var myAction31 :SKAction!
self.myAction30 = SKAction.repeatActionForever(puzzle30)
self.myAction31 = SKAction.repeatActionForever(puzzle31)
let group = SKAction.group([self.myAction30, self.myAction31])
self.runAction(group)
UPDATE: I've seen your update part, when you speak about "synchronize" probably you don't means the "running in parallel" actions.
So, if you want to run an action after another there is also:
self.myAction30 = SKAction.repeatActionForever(puzzle30)
self.myAction31 = SKAction.repeatActionForever(puzzle31)
let sequence = SKAction.sequence([self.myAction30, self.myAction31])
self.runAction(sequence)

Resources