Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving issues subclassing CCSprite. What did I miss?
    primarykey
    data
    text
    <p>I've recently picked up app writing as a hobby and I've run into a problem with my first app. My first app attempt is fairly simple...a domino game. I started out using an NSObject class to describe each tile, but I think I've decided that CCSprite is easier for me at the moment.</p> <p>The first step was creating an NSArray of all the tiles and then shuffling them. This is where I'm getting stuck....</p> <p><strong>Domino.h</strong> </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_trickvalue; NSString *str_tilename; NSString *str_mirrortilename; } @property int int_leading,int_trailing, int_suitrank, int_trickvalue; @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><strong>Domino.m</strong> </p> <pre><code>@implementation Domino @synthesize int_leading,int_trailing, int_suitrank, int_trickvalue, str_tilename, str_mirrortilename; //@synthesize char_tilename, char_mirrortilename; -(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><strong>helloworld.m</strong></p> <pre><code>// Import the interfaces #import "HelloWorldLayer.h" #import "Domino.h" // HelloWorldLayer implementation @implementation HelloWorldLayer +(CCScene *) scene { // 'scene' is an autorelease object. CCScene *scene = [CCScene node]; // 'layer' is an autorelease object. HelloWorldLayer *layer = [HelloWorldLayer node]; // add layer as a child to scene [scene addChild: layer]; // return the scene return scene; } // on "init" you need to initialize your instance -(id) init { if( (self=[super init] )) { //NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Domino *d00 =[[Domino alloc] init]; NSString *TileName= @"0-0.png"; NSString *MirrorName= @"0-0.png"; [d00 setTileName: TileName]; [d00 setMirrorName: MirrorName]; d00.int_leading=0; d00.int_trailing=0; . . . . . . . . movableSprites = [[NSMutableArray alloc] init]; //build initial array of tiles NSArray *uniquetiles = [NSArray arrayWithObjects: d00,d01,d02,d03,d04,d05,d06, d11,d12,d13,d14,d15,d16, d22,d23,d24,d25,d26, d33,d34,d35,d36, d44,d45,d46, d55,d56, d66, nil]; //shuffle integer array representing tile index number int tile[28]; // array of tile row ids; for (int i=0; i&lt;28; i++) { tile[i] = i; // fill the array in order } for (int i=0; i&lt;(27-1); i++) { int r = i + (arc4random() % (27-i)); // Random remaining position. int temp = tile[i]; tile[i] = tile[r]; tile[r] = temp; } int i=30; Domino *sprite =[[Domino alloc] init]; for(int h = 1; h &lt; 8; ++h) { for(int w=0;w&lt;4; ++w){ i=tile[(h-1)*4+(w)]; NSString *name=[[uniquetiles objectAtIndex:i]valueForKey:@"str_tilename"]; CGPoint spriteOffset = ccp(100+60*w, 45+25*h); NSLog(@" client Id : %@",[CCSprite spriteWithSpriteFrameName:name]); sprite=[CCSprite spriteWithSpriteFrameName:name]; sprite.scale=.50; sprite.int_leading=1; //program fails here </code></pre> <p>When I try to set the value of the tile, I end up getting a "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite setInt_leading:]" What am I doing different here than what I just did before when I defined d00?</p>
    singulars
    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.
 

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