Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to passing class argument to selector in objective C?
- //Class Tile
- @interface Tile : TouchableNode {
- NSString *val;
- }
- -(void) setVal:(NSString *)v
- {
- val = v;
- }
- -(NSString *) getVal
- {
- return val;
- }
- for(Tile *tile in player)
- {
- if (tile.getVal == @"P") {
- if (pauseStatus == 0) {
- pauseStatus = 1;
- [[CCDirector sharedDirector] pause];
- CGSize size = [[CCDirector sharedDirector] winSize];
- pauseLayer=[[CCLayer alloc] init];
- pauseLayer.anchorPoint=ccp(0,0);
- pauseLayer = [CCLayerColor layerWithColor: ccc4(0, 0, 255, 125) width: 300 height: 150];
- pauseLayer.position = ccp(size.width/2, size.height/2);
- pauseLayer.isRelativeAnchorPoint = YES;
- [self addChild: pauseLayer z:8];
- //Here are 2 two button that when user click it will have @"+" value or @"-"
- plusBtn = [CCMenuItemImage itemFromNormalImage:@"plus.png" selectedImage:@"plus.png" target:self selector:@selector(onPlus:)];
- minusBTn = [CCMenuItemImage itemFromNormalImage:@"minus.png" selectedImage:@"minus.png" target:self selector:@selector(onMinus:)];
- pauseMenu = [CCMenu menuWithItems:plusBtn, minusBTn, nil];
- [pauseMenu alignItemsHorizontally];
- [self addChild:pauseMenu z:10];
- }
- }
- }
- -(void)onPlus:(Tile *) set
- {
- NSString *plus = @"+";
- [set setVal:plus];
- }
- -(void)onMinus:(Tile *) set
- {
- NSString *minus = @"-";
- [set setVal:minus];
- }
- plusBtn = [CCMenuItemImage itemFromNormalImage:@"plus.png" selectedImage:@"plus.png" target:self selector:@selector(onPlus:)];
- plusBtn.userData = (void*)tile; // You may need a bridge cast in ARC
- minusBTn = [CCMenuItemImage itemFromNormalImage:@"minus.png" selectedImage:@"minus.png" target:self selector:@selector(onMinus:)];
- minusBTn.userData = (void*)tile;
- -(void)onPlus:(id)senderObj {
- CCNode *sender = (CCNode*)senderObj;
- Tile *myTile = (Tile*)sender.userData; // Again you may need a bridge cast here
- }
- @interface MyCustomCCMenuItemImage : CustomCCMenuItemImage
- @property (nonatomic, retain) Tile* tile;
- @end
- - (void)someMethod
- {
- for(Tile *tile in player)
- {
- plusBtn = [MyCustomCCMenuItemImage itemFromNormalImage:@"plus.png" selectedImage:@"plus.png" target:self selector:@selector(onPlus:)];
- plusBtn.tile = tile ;
- }
- }
- //Your handler
- -(void)onPlus:(id)sender
- {
- Tile *myTile = sender.tile;
- }
- [tile.getVal isEqualToString:@"P"]
Add Comment
Please, Sign In to add comment