2025-05-25

在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方法,其主要內容為選中一個機器人,必須反選其他機器人,任何時候隻能有一個機器人被選中.

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *