Animate SpriteKit node, not moving

53 Views Asked by At

I need to rotate a (green) line I have created using SpriteKit.

Immage

But I'm facing the following issue:

The action not work...when I call the func animate() nothing happen..

The following SKScene is used as material for a SCNNode... not sure if there is some limitation because this scene is used as material of SceneKit.

import Foundation
import SpriteKit
import SceneKit

class ECAM_APU {
    
    var apu_display : SKScene?
    
    
    
    init() {
        loadSKscene()
        makeLineEGT()
    }
    
    
    func loadSKscene(){ // load screenPFD
        let scene = SKScene(fileNamed: "/Asset.scnassets/ECAM SYSTEM/ECAM_APU.sks")!
        scene.scaleMode = .resizeFill
        
        apu_display = scene
        
    }
    
    
    func makeLineEGT(){
        guard let apu_display = apu_display else {
            return
        }
        
        guard let centerEGT = apu_display.childNode(withName: "EGT_POINT") else  {return}
        guard let zeroEGT = apu_display.childNode(withName: "EGT_POINT_ZERO") else  {return}
        let line = makeLine(startPos: centerEGT.position, endPos: zeroEGT.position, name: "EGT_LINE")
        
        apu_display.addChild(line)
    }
    
    func animate(){
        guard let apu_display = apu_display else {
            return
        }
        guard let line = apu_display.childNode(withName: "EGT_LINE") as? SKShapeNode else  {
            print("cantFind")
            return}
        
        let action = SKAction.rotate(byAngle: deg2rad(180), duration: 10)
        
        line.run(action)
        print("fatto")
    }
    
    func makeLine(startPos: CGPoint, endPos: CGPoint, name: String )->SKShapeNode {
        let path = CGMutablePath()
        path.move(to: startPos)
        path.addLine(to: endPos)
        let line = SKShapeNode(path: path)
        line.name = name
        line.strokeColor = .green
        line.fillColor = .green
        line.lineWidth = 5
        return line
    }
}

Thanks..

0

There are 0 best solutions below