Hello,
I am making a Vidoe Poker app. I currently have button sprites (CCSprite) on 2 separate layers; one layer has the deal/draw button that affects the cards being displayed, the pay table button, and the main menu button. I call this my Poker Layer.
The other layer has the bet increase and bet maximum buttons, which changes the bet and the user sees the current bet displayed. I call this my HUD Layer.
I would like to have on layer that handles all touches for the buttons and one layer that handles all touches for the cards. However, I do not have a good communication method between layers (children of the same Scene Parent). If the bet button is hit, I have to update the Current Bet label. If the deal button is hit, I have to update the cards and disable the bet buttons.
I am not sure how to accomplish this unless I make Global Flags that the button functions access and the other sprite functions poll. That seems to be a lot of setup when entering and exiting a scene. It seems like there should be a better way to communicate between layers of the same Scene.
Here is a little bit of code to hopefully clarify:
For the Poker Layer:
switch (TouchedSpriteTag) {
case kTagDeal:
[obj runAction: [CCFadeIn actionWithDuration:0.3]];//lets make the button fade in
[self schedule:@selector(ExitHand:)];
break;
case kTagDraw:
[obj runAction: [CCFadeIn actionWithDuration:0.3]];//lets make the button fade in
[self schedule:@selector(DrawHand:)] ;
break;
case kTagMenu:
[obj runAction: [CCFadeIn actionWithDuration:0.3]];//lets make the button fade in
[self schedule:@selector(MainMenu:)] ;
break;
For the HUD Layer
for (i = 0; i < count; i++)
{
TSprite * obj = [[TSprite allMySprites] objectAtIndex:i];
if (CGRectContainsPoint([obj rect], location) && [obj GetCanTrack])
{
if([obj tag] == kTagBetPlus) //if Card1 was touched
{
[obj runAction: [CCFadeIn actionWithDuration:0.3]];//lets make the button fade in
[self schedule:@selector(BetPlus:)] ;
}
else if([obj tag] == kTagBetMax) //if Card1 was touched
{
[obj runAction: [CCFadeIn actionWithDuration:0.3]];//lets make the button fade in
[self schedule:@selector(BetMax:)] ;
actionWithDuration:0.1 scale: 0.6f]];//lets make the button fade in
}
}
-(void)BetPlus: (id)sender {
[self unschedule:@selector(BetPlus:)] ;
if( [[GameController sharedGameController] getGameOver] == YES)
{
[[GameController sharedGameController] IncrGameBet] ;
int currentBet = [[GameController sharedGameController] GetGameBet] ;
[self UpdateBetLabel: [[NSNumber numberWithInt:currentBet] stringValue]];
[[SimpleAudioEngine sharedEngine] playEffect:@"coin_2.wav"];//play a sound
}
}
Thank you for any ideas.
Sat Back