Hey Guys,
Hope this is not a dumb problem that I can't seem to figure out. Here is the code I am working with:
@implementation SinglePlayArea
- (id)init
{
if ((self = [super init])) {
playerDeck = [[PlayerDeck alloc] init];
[playerDeck setupDeck];
[playerDeck shuffleDeck];
CCMenuItem *deckB = [CCMenuItemImage itemFromNormalImage:@"Icon.png" selectedImage:@"Icon.png" target:self selector:@selector(deckNewCards:)];
CCMenu *deckButton = [CCMenu menuWithItems:deckB, nil];
deckButton.position = ccp(350, 50);
[self addChild: deckButton];
}
return self;
}
- (void)deckNewCards:(id)sender
{
for (int i = 0; i < 4; i++)
{
Cards *card = [playerDeck.shuffledlist objectAtIndex:i];
CCTexture2D *cardTexture = [[CCTextureCache sharedTextureCache] addImage:[NSString stringWithFormat:@"%@", card.imagePath]];
card = [Cards cardWithTexture:cardTexture];
card.position = ccp( 30 + i * (i + 50), 160);
[self addChild:card z:(i - i * 2)];
}
}
The playerDeck is an array of 52 card objects that have 3 variables: Type, vaule and imagePath. The problem happens at
“CCTexture2D *cardTexture = [[CCTextureCache sharedTextureCache] addImage:[NSString stringWithFormat:@"%@", card.imagePath]];”
In the deckNewCards method. The debugger is saying that the variable for imagePath is out of scope. If I place the code from deckNewCards into my init method, the code works fine. Thanks for any help you can give or can point me in the right direction.