objective c - How can I get CCMenuItemSprite selector to call other layer void? -


the below code works great when i'm calling void in same .m file want selector go 2nd layer in scene 'moveupselected' void (which contains actions sprites movement). how can this?

hudlayer.m button code in layer communicate other layer

    self.dpad = [ccsprite spritewithfile:@"dpad.png"];     ccsprite *dpadselectedsprite = [ccsprite spritewithtexture:[dpad texture]];     dpadselectedsprite.color = ccgray;     //float dpadheight = flaresprite.texture.contentsize.height;     ccmenuitemsprite *dpadbuttons = [ccmenuitemsprite itemwithnormalsprite:dpad selectedsprite:dpadselectedsprite target:level1 selector:@selector(moveupselected)];     dpadbuttons.position = cgpointmake(size.width / 2, 150);     [menu addchild:dpadbuttons]; 

level1.m void in 2nd layer waiting called 1st layer button

- (void)moveupselected {     int yposition = self.player.position.y;     yposition += [self.player texture].contentsize.height/2;      cgsize size = [[ccdirector shareddirector] winsize];     if (yposition >= (size.height - [self.player texture].contentsize.height/2)) {         yposition = (size.height - [self.player texture].contentsize.height/2);     }      self.player.position = cgpointmake(self.player.position.x, yposition); } 

i have gamescene1.m holding both layers in separate files.

    +(id) scene {     ccscene *scene = [ccscene node];      hudlayer *hud = [hudlayer node];     [scene addchild:hud z:2];      level1 *layer = [level1 node];     [scene addchild:layer];      return scene; } 

please explain lines of code.

it hard understand want do. stephen mentioned in comment, "using void" , "void action" phrases have no sense. anyway, if want call instance's method on btn click, set target of menu item. in case

ccmenuitemsprite *dpadbuttons = [ccmenuitemsprite itemwithnormalsprite:dpad selectedsprite:dpadselectedsprite target:self selector:@selector(moveupselected)]; 

uses self target. change self.parent or other instance , menu item try call selector on target.

edit:

ccmenuitemsprite *dpadbuttons = [ccmenuitemsprite itemwithnormalsprite:dpad selectedsprite:dpadselectedsprite target:levelinstance selector:@selector(moveupselected)]; 

i edits tried use class object, not it's instance target. cannot find static methods.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -