Work with Community Window

 


1.Show Community Window

2.Handle Community Entry Visibility

3.Monitor Community In-Game Message

4.Pause Game when Community Window is displayed

5.Quick Post to Community

6.Handle Sound Event

7.Setting Community Language

1. Show Community Window

The Community Window is the main user interface of KTplay In-Game Community. Have an easy accessible Community Entry (where to call the show method) is critical for the success of the community.

 KTPlay.show();

[KTPlay show];

KTPlayC::show();

KTPlay.Show();

2. Handle Community Entry Visibility

Community Entry is where player invoke Community Window, so it need to be visible if Community is ready to use, vice versa, it need to be hidden when Community is not ready, and the following situations are Community entry need to be hidden.

  • It run on a not support device or device OS version.

  • The Community is Turn off by KTplay developer portal.

  • KTplay SDK initialization is not completed.

There are 2 ways to check if the Community is ready.

  • For Community Entry displayed by drawing, KTPlay.isEnabled status needed to be checked on every frame update.

if(KTPlay.isEnabled()){
    game.showKTButton(); //KTplay Community Entry UI drawing
 }

    if([KTPlay isEnabled]){
        [Game drawKTButton ];
    }

if(KTPlayC::isEnabled()){
     Game::drawKTButton();
}

     if(KTPlay.IsEnabled()){
     Game.DrawKTButton();
    }
  • For Community Entry not displayed by drawing (use standard UI), then Game need to monitor Community's availability status change.

KTPlay.setOnAvailabilityChangedListener(new KTPlay.OnAvailabilityChangedListener() {
            @Override
            public void onAvailabilityChanged(boolean enabled) {
                if(KTPlay.isEnabled()){
                    Game.showKTButton(); //show entry
                }else{
                    Game.hideKTButton(); //hide entry 
                }
            }
        });

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. Monitor Community In-Game Message

KTplay SDK will receive message from backend even they are in background (Community not displayed as when game is being played for example). The callback will provide community's status change information, such as message received, so that game can show visual effect to alert player, such as Red-dot on the Community Entry.

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. Pause Game when Community Window is displayed

It is recommended to pause the game running when Community Window is displayed, it will cover large area of screen estate, player likely not able to play the game effectively.

A callback is provided to inform game when Community Window is displayed.

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. Quick Post to Community

The method allows Game to post content to In-Game Community programmatically. One example is when player reach certain level, game can put together congratulation message, and ask Player to post to Community. Currently, 2 quick post methods are provided: 1. Image with Text, and 2. Video with Text.

  • Quick Post of Image

 KTPlay.shareImageToKT(imgPath ,
 "Game predefined title put in here",
  "Game predefined message put in here");

 [KTPlay shareImageToKT:imgPath title:@"Game predefined title put in here" description:@"Game predefined message put in here"];

 KTPlayC::shareImageToKT(imgPath,
 "Game predefined title put in here",
  "Game predefined message put in here");

KTPlay.ShareImageToKT(imgPath,
"Game predefined title put in here",
"Game predefined message put in here");
  • Quick Post of Video

 KTPlay.shareVideoToKT(videoPath, 
 "Game predefined title put in here",
 "Game predefined message put in here");

  [KTPlay shareVideoToKT:videoPath  title:@"Game predefined title put in here" description:@"Game predefined message put in here"];

 KTPlayC::shareVideoToKT(videoPath, 
 "Game predefined title put in here",
 "Game predefined message put in here");

 KTPlay.ShareVideoToKT(videoPath, 
 "Game predefined title put in here",
 "Game predefined message put in here");

6. Handle Sound Event

When Player use features with sound effect such as Voice-chat and video-replay, it will be confusing to them if the game is also playing background music at the same time. It is suggested to turn-off or turn-down Game's background sound when those feature is used.

A callback is provided to inform game for the sound start and stop event of sound-effect feature, so that game can make the necessary adjustment on its sound effect.

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. Setting Community Language

SDK supports the following languages (if not set using this method, Community will use device’s system language):

  • Arabic
  • English
  • Japanese
  • Korean
  • Simplified Chinese
  • Traditional Chinese-Taiwan
  • Traditional Chinese-Hong Kong
  • French
  • Italian
  • Spanish
  • Portuguese (Brazilian)

You can use set language method to change the language of Community Window, with the parameters format as below:

LanguageCode-LanguageScript-RegionCode

  • LanguageCode ISO 639 -1 2 digits language code, e.g. zh, en.
  • LanguageScript ISO 15924 4 digits language script, e.g. Hans, Hant.
  • RegionCode ISO 3166-1 2 digits region code, e.g. CN, US.

LanguageCode is mandatory field, whereas LanguageScript and RegionCode are optional. e.g. acceptable format are zh-Hant-HK, zh-Hans,zh-CN, zh.

String preferredLanguage="zh-CN"; //Preferred Language.
String alternateLanguage = null; //Alternative language, optional, will be used when preferred language is not supported by the SDK, if alternative language is also not supported, then community will use the device's system language.
KTPlay.setLanguage(preferredLanguage,alternateLanguage);

NSString* preferredLanguage=@"zh-CN"; //Preferred Language.
NSString* alternateLanguage = nil;  //Alternative language, optional, will be used when preferred language is not supported by the SDK, if alternative language is also not supported, then community will use the device's system language..
[KTPlay setLanguage: preferredLanguage alternateLanguage: alternateLanguage];

String preferredLanguage=@"zh-CN"; //Preferred Language.
String alternateLanguage = null; //Alternative language, optional, will be used when preferred language is not supported by the SDK, if alternative language is also not supported, then community will use the device's system language.
KTPlayC::setLanguage(preferredLanguage,alternateLanguage);

string preferredLanguage="zh-CN"; //Preferred Language.
string alternateLanguage = null;  //Alternative language, optional, will be used when preferred language is not supported by the SDK, if alternative language is also not supported, then community will use the device's system language.
KTPlay.SetLanguage(preferredLanguage,alternateLanguage);

If the language set by API is a SDK supported language, then the language will be used for Community display.

If both the preferred and alternative language set by API is not a SDK supported Language, but device is using a SDK Supported Language, then the device’s Language will be used for Community display.

If both the preferred and alternative language set by API is not a SDK supported Language, nor the device is using a SDK Supported Language, then Community will use English for Community display.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.