现在我的代码提供了7张扑克牌。如果按下了扑克牌,则移动将卡从playerCard
阵列中移除并将其添加到playedCards
阵列。问题是,我使用touchesBegan
方法中的SKNode移动卡片我的目标;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
if ([node isKindOfClass:[CardSpriteNode class]]) {
好的,没问题,卡片向上移动。问题是,playerCards
中剩下的所有其他牌现在都需要像原来那样移动,即收紧。这是我对他们之间距离的公式;
int cardsLaid = i * (cardDisplay.size.width / 3);
所以我现在可以获得最初显示的卡片和被触摸的卡片,以便在它们之间形成一个很好的间隙。
我需要做的是在卡片之间的一张牌被移动后将卡片移回一个很好的间隙
for (int i = 0; i < [playerCards count]; i++) {
int cardsLaid = i * (cardDisplay.size.width / 3);
CGPoint forPoint = CGPointMake((0.5 - (self.frame.size.width / 4)) + cardsLaid, 0.0);
playerCards[i] //Here I need to target each skspritenode.name for each playerCards
[??? runAction:[SKAction moveTo:forPoint duration:0.6]];
}
所以我需要使用playerCards
MutableArray中保存的名称来定位每个SKSpritenode.name。然后,一旦我针对spritenode,我需要将其移动到???
所在的位置。
这是我的整个touchesBegan
方法,如果有帮助的话。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
if ([node isKindOfClass:[CardSpriteNode class]]) {
int add = (int)[playerCards count] * (cardDisplay.size.width / 3);
CGPoint origPos = CGPointMake(-self.frame.size.width/2.8 + add, -218);
if ([cardsPlayed containsObject:node.name]) {
//Card is already played, return to original position and remove from array.
CGPoint point = origPos;
[node runAction:[SKAction moveTo:point duration:0.6]];
node.zPosition = zPosCount;
zPosCount += 1;
[cardsPlayed removeObject:node.name];
[playerCards addObject:node.name];
NSLog(@"this ran");
} else {
//Card is not already played, position to add card and add to array.
amountOfCardsLaid = (int)[cardsPlayed count] * (cardDisplay.size.width / 3);
CGPoint point = CGPointMake((0.5 - (self.frame.size.width / 4
)) + amountOfCardsLaid, 0.0);
[node runAction:[SKAction moveTo:point duration:0.6]];
node.zPosition = zPosCount;
zPosCount += 1;
[playerCards removeObject:node.name];
[cardsPlayed addObject:node.name];
for (int i = 0; i < [playerCards count]; i++) {
int cardsLaid = i * (cardDisplay.size.width / 3);
CGPoint forPoint = CGPointMake((0.5 - (self.frame.size.width / 4)) + cardsLaid, 0.0);
playerCards[i]
[??? runAction:[SKAction moveTo:forPoint duration:0.6]];
}
}
//Hide.Unhide buttons
if ([cardsPlayed count] == 0) {
if (addButton.hidden == FALSE) addButton.hidden = true;
if (cancelButton.hidden == FALSE) cancelButton.hidden = true;
} else {
if (addButton.hidden == TRUE) addButton.hidden = false;
if (cancelButton.hidden == TRUE) cancelButton.hidden = false;
}
}
}
我需要关闭的差距位于底部playerCards
答案 0 :(得分:0)
SKNode *tempNode = [self childNodeWithName:playerCards[i]];
几天后。 FML