当我在同一个 .m 文件中调用 void 时,下面的代码效果很好,但我希望我的选择器转到场景中的第二层以获取其“MoveUpSelected”void(其中包含我对精灵移动的操作)。我怎样才能做到这一点?
HUDLayer.m 我的图层中的按钮代码,用于与其他图层通信
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 我的第 2 层中的空白等待被第 1 层按钮调用
- (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);
}
我有一个 GameScene1.m 将两个图层保存在单独的文件中。
+(id) scene
{
CCScene *scene = [CCScene node];
HudLayer *HUD = [HudLayer node];
[scene addChild:HUD z:2];
Level1 *layer = [Level1 node];
[scene addChild:layer];
return scene;
}
请用代码行解释。