SKShapeNode select X amount

42 views Asked by At

Question

I'm developing some poker software ~ purely for fun.

Now when it comes to the chips, I'm having a nightmare. One positioning them, two the denominations and THREE Selecting the ones I'll need! This seems almost impossible with my current design.

Basically, I draw an skshapenode give it the name of the denomination and the player name. However, this chip can be drawn 50 times with the same name.

When I come to animating these chips, I can only see a wall of impossibility..

once I've made a function to choose the right denominations of chips to use for a call or raise etc, how will I even begin to write this pseudo code?

I require 2 large chips, 1 small chip and 2 medium chips {
    SKNode *node = [self childnodewithname:denomination, playername];

    runaction..
}

Baring in mind, I'll only need to take 2 of the 20 that are there in the chip stack.. As well as change the ownership of the chip..

is this possible? or am I seriously overcomplicating the issue..?

1

There are 1 answers

1
Tobi On BEST ANSWER

You need to rework your solution a little bit. I would do something like this:

First, subclass a SKSpriteNode (or SK whatever node you like) to make a chip:

Chip.h

@interface Chip : SKSpriteNode

@property (nonatomic, retain) NSString *player;
@property int denomination;

@end

Chip.m

@implementation Chip
- (id)initWithColor:(UIColor *)color size:(CGSize)size
{
  if(self = [super initWithColor:color size:size])
  {
    self.name = @"chip";
  }

  return self;
}

@end

Now you've got something you can reasonably enumerate and inspect.

Add a bunch of chips to your game scene:

GameScene.m

-(void)didMoveToView:(SKView *)view {
  for(int i = 0; i < 50; i++)
  {
    Chip *chip = [[Chip alloc] initWithColor:[SKColor greenColor]
                                        size:CGSizeMake(100.0, 100.0)];

    chip.player = @"some player";
    chip.denomination = 10;

    [self addChild:chip];
  }
}

Then when it's time to pop off a certain number of the chips:

 -(void)popChipsFromPlayer:(NSString *)playerName
           ofDenomination:(int)denomination
            numberOfChips:(int)numChips
{
  __block int i;

  [self enumerateChildNodesWithName:@"chip"
                         usingBlock:^(SKNode *node, BOOL *stop) {
                           Chip *chip = (Chip *)node;
                           if(chip.denomination == denomination &&
                              [playerName isEqualToString:chip.player])
                           {
                             if(i==numChips)
                               return;

                             SKAction *moveUp = [SKAction moveByX:0.0
                                                                y:200.0
                                                         duration:3];

                             [chip runAction:moveUp];

                             i++;
                           }
                         }];
}

Call the method:

  [self popChipsFromPlayer:@"some player"
            ofDenomination:10
             numberOfChips:3];