cocos2d Objective-C adding multiple images to table cells -
i'm developing game setup settings menu in form of table cells. click on settings button in main menu , setting panel in form of table cell pop up. able load single image table shown below. need load different images each table cell. table
my code looks following:
#import "ccnode.h" @interface cgtableview : ccnode @property (nonatomic, assign)cgfloat height; - (instancetype)inittableviewwithidentifier:(nsstring *)identifier withblock:(void (^)(nsstring *identifer))block; - (instancetype)inittableviewwithidentifier:(nsstring *)identifier imagename:(nsstring *)imagename withblock:(void (^)(nsstring *identifer))block; @end
then in implementation following:
#import "cgtableview.h" #import "cgbutton.h" @interface cgtableview () @property (nonatomic, copy)void (^block)(nsstring *); @property (nonatomic, strong)nsstring *identifier; @end @implementation cgtableview - (instancetype)inittableviewwithidentifier:(nsstring *)identifier imagename:(nsstring *)imagename withblock:(void (^)(nsstring *identifer))block { self = [super init]; if (!self) return nil; _block = block; _identifier = identifier; self.contentsizetype = ccsizetypemake(ccsizeunitnormalized, ccsizeunitpoints); self.contentsize = cgsizemake(0.9, 1.0); [self addchild:[self buttonimage]]; return self; } - (instancetype)inittableviewwithidentifier:(nsstring *)identifier withblock:(void (^)(nsstring *identifer))block { self = [super init]; if (!self) return nil; return [self inittableviewwithidentifier:identifier imagename:@"button.png" withblock:block]; } - (ccsprite *)buttonimage { return [self buttonwithimagenamed:@"button.png" position:ccp(0.15, 0.5) scale:0.6]; } - (ccsprite *)buttonwithimagenamed:(nsstring *)imagenamed position:(cgpoint)position scale:(float)scale { ccsprite *sprite = [ccsprite spritewithimagenamed:imagenamed]; sprite.positiontype = ccpositiontypenormalized; sprite.position = position; sprite.scale = scale; return sprite; }
Comments
Post a Comment