Reputation: 966
So I'm at the point in my app where I need to replace the image of a sprite and I think I know how to do it, but I'm having trouble implementing it. Basically, I'm making a domino game and I need to be able to flip the domino over so you can see the numbers.
Starting with my domino.h file....
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface Domino : CCSprite {
int int_leading;
int int_trailing;
int int_suitrank;
int int_playerid;
NSString *str_tilename;
NSString *str_mirrortilename;
}
@property int int_leading,int_trailing, int_playerid,
@property(nonatomic, retain) NSString *str_tilename;
@property(nonatomic, retain) NSString *str_mirrortilename;
-(void) print;
-(void) setTileName: (NSString *) theTileName;
-(void) setMirrorName: (NSString *) theMirrorName;
-(NSString *) str_tilename;
-(NSString *) str_mirrortilename;
@end
and then my .m file...
#import "Domino.h"
@implementation Domino
@synthesize int_leading,int_trailing, str_tilename, str_mirrortilename, int_playerid;
-(void) print {
NSLog (@"%i/%i", int_leading, int_trailing);}
-(void) setTileName: (NSString *) theTileName;
{
str_tilename=[[NSString alloc] initWithString: theTileName];
}
-(void) setMirrorName: (NSString *) theMirrorName;
{
str_mirrortilename=[[NSString alloc] initWithString: theMirrorName];
}
-(NSString *) str_tilename
{
return str_tilename;
}
-(NSString *) str_mirrortilename
{
return str_mirrortilename;
}
@end
Finally, in my game layer...
Domino *d06 =[[Domino alloc] initWithSpriteFrameName:@"blank.png"];
TileName= @"0-6.png";
MirrorName= @"6-0.png";
[d06 setTileName: TileName];
[d06 setMirrorName: MirrorName];
d06.int_leading=0;
d06.int_trailing=6;
At this point, I add all the dominoes together into a large mutable array that tracks which ones are still available for players to pick. The problem I'm having is that I either haven't found how to pull out the "TileName" from the mutable array, or maybe I have found it, but not understood it.
If I'm in a For loop, I would think the code should be something like
NSString *temp1=[[[movableSprites objectAtIndex:i]valueForKey:@"str_tilename"]string];
But this just results in the program crashing. Can you point me in the right direction?
Upvotes: 0
Views: 136
Reputation: 1259
NSString *temp1=[(Domino *)[movableSprites objectAtIndex:i] str_tilename];
I think using this code will solve your stuff... Check for the syntax.. Hope this helps.. :)
Upvotes: 1