OtakuFitness
OtakuFitness

Reputation: 554

How can I load multiple objects in SceneKit?

I've made a scn file called arrowsign.scn which contains a arrow like the picture below: enter image description here

I wrote a piece of code to load the arrow object:

SCNNode *node = [SCNNode node];
SCNNode *a[10];
for (int i = 0;i<10;i++){
    a[i] = [scene.rootNode childNodeWithName:@"arrowsign" recursively:NO];//just one arrow in arrowsign.scn
    a[i].scale = SCNVector3Make(0.15f, 0.15f, 0.15f);
    a[i].position = SCNVector3Make(1+i, 0, 0);
    [node addChildNode:a[i]];
}
[scene.rootNode addChildNode:node];

Ideally there will be a row of arrows displaying in the screen. However, there is just one arrow displaying. How can I achieve my goal?

Upvotes: 0

Views: 1173

Answers (2)

HaoDong
HaoDong

Reputation: 349

I think you can simply clone node

let sphereNode2 = sphereNode.clone()
sphereNode2.position = SCNVector3(x: 0, y: 0, z: -20)
scene.rootNode.addChildNode(sphereNode2)

Upvotes: 2

Karl Sigiscar
Karl Sigiscar

Reputation: 299

Instead of creating new SCNNode instances, create SCNReferenceNode instances in order to load your .scn file into them.

Upvotes: 2

Related Questions