在Xcode中打开Robot.h文件添加如下2个方法:
-(void)moveArm:(MoveDirection)direction; -(void)armShoot;
在Robot.m中实现这2个方法:
-(void)armShoot{ [_arm armShoot]; } -(void)moveArm:(MoveDirection)direction{ [_arm moveArm:direction]; }
由于玩家点击机器人时需要选中该机器人,所以要添加touchBegan方法:
-(void)touchBegan:(CCTouch *)touch withEvent:(CCTouchEvent *)event{ self.isSelected = YES; LevelRestrict *lr = [LevelRestrict sharedInstance]; lr.selectedRobot = self; [[MainScene sharedInstance] selectRobot:self]; //将触碰事件向下层节点传递 //[super touchBegan:touch withEvent:event]; }
现在在回到MainScene.m中添加selectRobot方法,其主要内容为选中一个机器人,必须反选其他机器人,任何时候只能有一个机器人被选中.