我有以下幾點:什麼是增加現有精靈的最佳途徑孩子精靈的
- 稱爲「_background」
- 3×精靈「C4」,D5" 和‘HJ’的 後臺精靈
這三個精靈分別添加到背景上,然後雙擊它,想讓它們同時拖動到屏幕上的另一個位置,同時它們保持相同的順序,
我已完成了近,上班的唯一方法是使用下面的代碼:
- (void)tap2TouchesGesture:(UITapGestureRecognizer *)sender {
SKNode *removeNode = [_background childNodeWithName:@"C4"];
CGPoint aPos = removeNode.position;
[removeNode removeFromParent];
SKSpriteNode *topNode = [SKSpriteNode spriteNodeWithImageNamed:@"C4"];
topNode.position = aPos;
topNode.zPosition = 100;
topNode.name = @"C4";
[_background addChild:topNode];
removeNode = [_background childNodeWithName:@"D5"];
[removeNode removeFromParent];
SKSpriteNode *vv = [SKSpriteNode spriteNodeWithImageNamed:@"D5"];
vv.position = CGPointMake(-10, -10);
vv.zPosition = -10;
vv.userInteractionEnabled = NO; // just testing
vv.name = @"D5";
[topNode addChild:vv];
removeNode = [_background childNodeWithName:@"Hj"];
[removeNode removeFromParent];
vv = [SKSpriteNode spriteNodeWithImageNamed:@"Hj"];
vv.position = CGPointMake(-20, -20);
vv.zPosition = -50;
vv.userInteractionEnabled = NO; // just testing
vv.name = @"Hj";
[topNode addChild:vv];
}
處理上面的代碼,我可以移動精靈的包,但目前的問題之後是父,C4,做似乎不是最重要的。選擇C4的唯一方法是點擊任何其他精靈之外的部分,不包括_background。
我想這不是執行此操作的最佳方法,所以我想請教如何正確執行此操作的一些幫助。另外,所以我可以通過點擊整個精靈來選擇C4。
我知道,但我不想使用Cocos2D,因爲我使用並學習SpriteKit,然後將它轉換爲KoboldKit。 – PeterK
抱歉,我打算說SKNode不是CCNode。無論原理是否相同。 – LearnCocos2D
我知道,你以前給我的答案,但我不能讓它正常工作,添加一個SKNode容器。你能以正確的方式讓我看看代碼嗎? – PeterK