How to access specific child node Scenekit

ε祈祈猫儿з 提交于 2019-12-13 03:15:09

问题


So in my application, you can think that it is similar to blackjack. There is a deck of 52 cards, and you reuse the same design on the back of the card, but it has different card faces such as Ace Spade, 2 Diamond and etc.

So in my Scenekit, I created a scene to specifically design 1 card. I will then duplicate it in my main scene 52 times. I also uniquely identify each individual parent node with a specific name such as Card1, Card2, Card3 and etc.

In my View Controller, I do the act of shuffling the cards in my code, and populate the images of the card face. However, when I tried assigning Card1 with Ace Spade, the rest of the 51 cards are also assigned with Ace Spade.

CardScene: Contains a single card that has a plain front, but designed back of the card.

Player1Scene: Adding CardScene to this scene, and duplicate it, because I have more than 2 cards. I'm naming my identity Player1MyCard1, Player1MyCard2 and etc in this scene.

MainScene: Contains miscellaneous stuff, including Player1Scene. The codes you see below is done on this scene.

Problem

I can't seem to uniquely assign Card1 with Ace Spade, and Card2 with other card faces. What I'm facing is every card faces are assigned with Ace Spade. Below is my code where I try to assign specific faces to specific cards.

func SetupNodes(){
    player1MyCard1 = scene.rootNode.childNode(withName: "Player1MyCard1", recursively: true)!
    print(player1MyCard1.name)
    cardFace = player1MyCard1.childNode(withName: "cardFace", recursively: true)!

    let material = SCNMaterial()
    material.diffuse.contents = UIImage(named: "1Thousand")
    material.locksAmbientWithDiffuse = true

    let whiteMaterial = SCNMaterial()
    whiteMaterial.diffuse.contents = UIColor.white
    whiteMaterial.locksAmbientWithDiffuse = true

    cardFace.geometry?.materials = [material, whiteMaterial, whiteMaterial, whiteMaterial, whiteMaterial, whiteMaterial]
}

来源:https://stackoverflow.com/questions/50849501/how-to-access-specific-child-node-scenekit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!