首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SKSpriteNode靶向

SKSpriteNode靶向
EN

Stack Overflow用户
提问于 2015-02-17 12:56:35
回答 1查看 65关注 0票数 0

所以现在我的代码显示了7张扑克牌。如果按下扑克牌,它将从playerCard数组中移除该卡并将其添加到playedCards数组中。问题是,是用SKNode在touchesBegan方法中移动卡片;

代码语言:javascript
运行
复制
-(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中剩下的所有其他卡现在都需要移动,也就是(收紧),就像原来的那样。这是我关于他们之间距离的公式;

代码语言:javascript
运行
复制
int cardsLaid = i * (cardDisplay.size.width / 3);

所以我现在可以得到最初显示的卡片和被触摸的卡片,在它们之间形成一个很好的差距。

我需要做的是把卡片移回一个很好的间隙,在它们之间的一张牌被移动之后,

代码语言:javascript
运行
复制
        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中的名称来针对每个MutableArray。然后,一旦我锁定了一个spritenode,我就需要将它移到???所在的位置。

这是我的整个touchesBegan方法,如果有帮助的话。

代码语言:javascript
运行
复制
-(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

EN

回答 1

Stack Overflow用户

发布于 2015-02-17 13:17:23

代码语言:javascript
运行
复制
SKNode *tempNode = [self childNodeWithName:playerCards[i]];

几天后。fml

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28562056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档