我正在尝试在SceneKit中构建一个塔防游戏。我在地图上的瓷砖中添加了一个模型,但它从未在正确的位置创建。我使用自定义模型并进行缩放。
+ (BasicAttackTower *)CreateTower { // return a single tower
SCNScene * towerScene = [SCNScene sceneNamed:@"basicattacktower.dae"];
SCNNode * node =[towerScene.rootNode childNodeWithName:@"SketchUp" recursively:NO ];
SCNAction * action = [SCNAction rotateByX:0 y:0 z:10 duration:1];
SCNAction * repeatAction = [SCNAction repeatActionForever:action];
for(int i=1;i<[node.childNodes count]-1;i++){
[[node.childNodes objectAtIndex:i] runAction:repeatAction];
}
node.scale = SCNVector3Make(0.04, 0.04, 0.04);
BasicAttackTower * tower = [BasicAttackTower node];
[tower addChildNode:node];
return tower;
}
- (void)AddTower:(Tower *)tower {// add tower on tile
tower.position = SCNVector3Make((self.position.x), (self.position.y), 2);
[self addChildNode:tower];
self.towerOnTile = tower;
}