社区

 

1.显示社区窗口

2.检查KTplay是否可用

3.监听社区是否有新的未读消息

4.当社区显示时暂停游戏

5.发布内容到社区

6.处理社区声音事件

7.设置社区语言

1. 显示社区窗口

社区窗口是KTplay的主要用户界面,建议把社区入口设计在明显的位置。

 KTPlay.show();

[KTPlay show];

KTPlayC::show();

KTPlay.Show();

2. 检查KTplay是否可用

KTplay服务在下列情况下不可用:

  • 运行在不支持的设备上(低端设备或操作系统版本过低)
  • 开发者后台关闭了KTplay功能
  • SDK初始化未完成

当KTplay不可用时,建议在游戏中隐藏社区入口。

  1. 实时检查KTplay可用状态
    如果你的社区入口是每帧刷新的,调用KTPlay的isEnabled方法检测社区可用状态,仅在可用时绘制入口。

if(KTPlay.isEnabled()){
    //KTplay Community Entry UI drawing

    game.showKTButton();  
    }

    if([KTPlay isEnabled]){
    //KTplay Community Entry UI drawing

        [Game drawKTButton ];
    }

if(KTPlayC::isEnabled()){
    //KTplay Community Entry UI drawing

     Game::drawKTButton();
}

     if(KTPlay.IsEnabled()){
     //KTplay Community Entry UI drawing

     Game.DrawKTButton();
    }
  1. 监听社区可用状态变更
    如果你的社区入口不是每帧刷新,可以监听社区可用状态变更接口,在社区可用状态变更时显示/隐藏社区入口。

KTPlay.setOnAvailabilityChangedListener(new KTPlay.OnAvailabilityChangedListener() {
            @Override
            public void onAvailabilityChanged(boolean enabled) {
                         //enabled, i.e. community Entry can be shown

            }
        });

KTAvailabilityChangedBlock availabilityChangedBlock =  ^(BOOL isEnabled){
         //isEnabled, i.e. community Entry can be shown
    }];

[KTPlay setAvailabilityChangedBlock: availabilityChangedBlock];

void availabilityChangedCallback(bool isEnabled){
    //isEnabled i.e. community Entry can be shown
}

KTPlayC::setAvailabilityChangedCallback(availabilityChangedCallback);

KTPlay.SetAvailabilityChangedDelegate ((bool isEnabled) => {
        //isEnabled i.e. community Entry can be shown
        });

3. 监听社区是否有新的未读消息

KTplay 接收到新的未读消息时会回调给游戏,建议游戏使用一些视觉效果在社区入口上,以便更好的提醒玩家。例如在社区入口上绘制小红点。未读消息包括新的奖励,是否有其他用户回复了我发布的话题等。

KTPlay.setOnActivityStatusChangedListener(new OnActivityStatusChangedListener() {
    @Override
    public void onActivityChanged(boolean hasNewActivity) {
        if(hasNewActivity){
        Game.ShowKTTip(); //show effect for status change
        }else{
        Game.HideKTTip(); //hide effect for status change
            }
         }
     });
    

KTActivityStatusChangedBlock activityStatusChangedBlock = ^(BOOL hasNewActivities) {
        if(hasNewActivities){
            [Game showKTTip]; //show effect for status change  
        }else{
            [Game hideKTTip]; //hide effect for status change
        }
}
[KTPlay setActivityStatusChangedBlock: activityStatusChangedBlock];

void activityStatusChanged(bool hasNewActivities) {
    if(hasNewActivities) {
        //show effect for status change  
    } else {
        //hide effect for status change
    }
}

KTPlayC::setActivityStatusChangedCallback(activityStatusChanged);

KTPlay.SetActivityStatusChangedDelegate ((bool hasActivityStatus) => {
    if(hasNewActivities) {
        //show effect for status change  
    } else {
        //hide effect for status change
    }
    });

4. 当社区显示时暂停游戏

当社区窗口显示时,建议暂停游戏。

SDK在窗口打开/关闭时提供了回调方法

KTPlay.setOnAppearListener(new OnAppearListener() {
     @Override
    public void onAppear() {
        Game.Pause();//Pause Game
    }
   });
   
   KTPlay.setOnDisappearListener(new OnDisappearListener() {
    @Override
    public void onDisappear() {
        Game.resume();//Resume Game
    }
    });

KTViewDidAppearBlock pauseBlock = ^(){
        [Game pause];
}
[KTPlay setViewDidAppearBlock:pauseBlock];


KTViewDidDisappearBlock resumeBlock = ^(){
        [Game resume];
}
[KTPlay setViewDidDisappearBlock:resumeBlock];

  void viewDidAppearCallback(){
     Game::pause();
  }
    KTPlayC::setViewDidAppearCallback(viewDidAppearCallback);
    

    void viewDidDisappearCallback() {
    Game::resume();
    }
    KTPlayC::setViewDidDisappearCallback(viewDidDisappearCallback);

KTPlay.SetViewDidAppearDelegate (() => {
            Game.Pause();
        });
KTPlay.SetViewDidDisappearDelegate (() => {
            Game.Resume();
        });

5. 发布内容到社区

SDK提供接口可以快速发布下列内容到社区:

  • 游戏截图
  • 图片
  • 视频

发布游戏截图

KTPlay.shareScreenshotToKT("Game predfined title put in here",
"Game predfined message put in here");

 [KTPlay shareScreenshotToKT:@"Game predfined title put in here" description:@"Game predfined message put in here"];

KTPlayC::shareScreenshotToKT("Game predfined title put in here",
"Game predfined message put in here");

KTPlay.ShareScreenshotToKT("Game predfined title put in here",
"Game predfined message put in here");

发布图片

 KTPlay.shareImageToKT(imgPath ,
 "Game predfined title put in here",
  "Game predfined meesage put in here");

 [KTPlay shareImageToKT:imgPath title:@"Game predfined title put in here" description:@"Game predfined meesage put in here"];

 KTPlayC::shareImageToKT(imgPath ,
 "Game predfined title put in here",
  "Game predfined meesage put in here");

KTPlay.ShareImageToKT(imgPath,
"Game predfined title put in here",
"Game predfined meesage put in here");

发布视频

 KTPlay.shareVideoToKT(videoPath, 
 "Game predfined title put in here",
 "Game predfined meesage put in here");

  [KTPlay shareVideoToKT:videoPath  title:@"Game predfined title put in here" description:@"Game predfined meesage put in here"];

 KTPlayC::shareVideoToKT(videoPath, 
 "Game predfined title put in here",
 "Game predfined meesage put in here");

 KTPlay.ShareVideoToKT(videoPath, 
 "Game predfined title put in here",
 "Game predfined meesage put in here");

6. 处理社区声音事件

当玩家在社区内触发多媒体功能时(如聊天和播放语音),社区声音会和游戏声音混淆。建议游戏监听社区声音播放时关闭游戏音效。

KTPlay.setOnSoundStartListener(new KTPlay.OnSoundStartListener() {
            @Override
            public void onSoundStart() {
                //turn-down or turn off game's sound here
            }
        });

        KTPlay.setOnSoundStopListener(new KTPlay.OnSoundStopListener() {
            @Override
            public void onSoundStop() {
                //restore game's sound level here
            }
        });

[KTPlay setSoundStartBlock:^{
       //turn-down or turn off game's sound 
    }];
    
    [KTPlay setSoundStopBlock:^{
        //restore game's sound level here
    }];

void ktSoundStart(){
     //turn-down or turn off game's sound 
  }
    KTPlayC::setSoundStartCallback(ktSoundStart);
    

    void ktSoundStop() {
    //restore game's sound level here
    }
    KTPlayC::setSoundStopCallback(ktSoundStop);

KTPlay.SetSoundStartDelegate (() => {
        //turn-down or turn off game's sound 
        });
        
        KTPlay.SetSoundStopDelegate (() => {
        //restore game's sound level here
        });

7. 设置社区语言

SDK目前支持下列语言(根据用户设置的系统语言自动选择):

  • 英文
  • 简体中文
  • 繁体中文-台湾
  • 繁体中文-香港
  • 日文
  • 韩文
  • 阿拉伯语
  • 法语
  • 西班牙语
  • 意大利语
  • 葡萄牙语(巴西)

你可以调用接口更改语言,语言参数需遵循下列格式:

LanguageCode-LanguageScript-RegionCode

  • LanguageCode ISO 639 -1 2位语言代码,如zh,en。
  • LanguageScript ISO 15924 4位语言变体代码,如Hans,Hant。
  • RegionCode ISO 3166-1 2位区域代码,如CN,US

其中, LanguageCode 部分必须提供, LanguageScript RegionCode 部分可选。如zh-Hant-HK,zh-Hans,zh-CN,zh均可。

String preferredLanguage="zh-CN"; //Preferred Language.
String alternateLanguage = null; //Preserved.
KTPlay.setLanguage(preferredLanguage,alternateLanguage);

NSString* preferredLanguage=@"zh-CN"; //Preferred Language.
NSString* alternateLanguage = nil; //Preserved.
[KTPlay setLanguage: preferredLanguage alternateLanguage: alternateLanguage];

String preferredLanguage=@"zh-CN"; //Preferred Language.
String alternateLanguage = null; //Preserved.
KTPlayC::setLanguage(preferredLanguage,alternateLanguage);

string preferredLanguage="zh-CN"; //Preferred Language.
string alternateLanguage = null; //Preserved.
KTPlay.SetLanguage(preferredLanguage,alternateLanguage);
还有其它问题?提交请求

0 评论

登录写评论。