Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get NSString values from an Mutable Object Array?
    primarykey
    data
    text
    <p>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.</p> <p>Starting with my domino.h file.... </p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #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 </code></pre> <p>and then my .m file...</p> <pre><code>#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 </code></pre> <p>Finally, in my game layer...</p> <pre><code>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; </code></pre> <p>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.</p> <p>If I'm in a For loop, I would think the code should be something like </p> <pre><code> NSString *temp1=[[[movableSprites objectAtIndex:i]valueForKey:@"str_tilename"]string]; </code></pre> <p>But this just results in the program crashing. Can you point me in the right direction?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload