SKLabel and UIImage location

Hello,


I am a question for location with SKLabel and UIImage in sceneView.


I created a SKLabel and UIImage in my Gamescene and my problem is the location for them.


When set the same location.x for UIIMage and SKLabel, they are placed in different places ...


Here is my code for SKLabel:



        scoreLabel = SKLabelNode(text: "Score: 0")
        scoreLabel.position = CGPoint(x: view.frame.maxX - 20, y: VieLabel.frame.minY - 60)
        scoreLabel.fontName = "AmericanTypewriter-Bold"
        scoreLabel.fontSize = 15
        scoreLabel.fontColor = UIColor.black
        score = 0
        scoreLabel.zRotation =  -CGFloat(Double.pi/2)
           
self.addChild(scoreLabel)



Here is my code for UIImage:


let imageName = "BalleFusil.png"
            let image = UIImage(named: imageName)
            let LogoArme = UIImageView(image: image!)
            view!.superview!.addSubview(LogoArme)
            LogoArme.frame.size.height = scoreLabel.frame.height
            LogoArme.frame.size.width = LogoArme.frame.height/2
            LogoArme.frame.origin.x = scoreLabel.frame.origin.x
            LogoArme.frame.origin.y = (self.view?.frame.height)! - scoreLabel.frame.origin.y



Thank you for your help !

Replies

Clarification:


My UIImage is created in the :

overridefunc update(_ currentTime: TimeInterval) {



My SKLabel is created in the :

overridefunc didMove(to view: SKView) {


Thank

If I understand, LogoArme.frame is relative to the superview


            view!.superview!.addSubview(LogoArme)
            LogoArme.frame.origin.x = scoreLabel.frame.origin.x


But scoreLabel.frame is relative ti view

        scoreLabel.position = CGPoint(x: view.frame.maxX - 20, y: VieLabel.frame.minY - 60)


So, they origin.x has the same value but in 2 coordinaates systems, of view and of superview.


Should show more complete code to confirm.

__________________________________ The superview

| |

| x LogoArme | LogoArme is @ (20, 20) in superview

| |

| ____________________ | Same value, different position on screen

| | | |

| | x scoreLabel | | scoreLabel is @ (20, 20) in view

| | | |

| | | |

| | | |

| |___________________| |

| |

| |

|_________________________________|

Thank for your reponse, what do you recommend me ? view or superview ?

I would add to the view, not superview. But I have not tested.

Thank for your answers