question

jungHwan avatar image
jungHwan asked

Do you have any plans to launch a PlayFab module in the Cocos Store?

I'm making a game with Cocos Creator. I'd like to use Azure Playfab. Do you have any plans to launch a PlayFab module in the Cocos Store?

https://store.cocos.com/app/en

sdksLeaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Xiao Zha avatar image
Xiao Zha answered

Currently, PlayFab doesn’t have plan to launch a PlayFab modules into Cocos Store. But since CocosCreator supports both JavaScript and TypeScript programming languages, you may refer to NodeJS quickstart - PlayFab | Microsoft Learn to install and use “playfab-sdk” in your project.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jungHwan avatar image jungHwan commented ·

I tried following nodejs quick start through npm install, but cocoscreator doesn't support it.

I posted it on the forum of Cocos Creator, but I received an answer to make it through the corresponding native SDKs for Android and iOS native Plugin.

https://discuss.cocos2d-x.org/t/cocoscreator3-8-0-playfab-undefined/59447

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

Since CocosCreator using TypeScript which is a statically typed language, and it may require type declaration files (.d.ts files) to understand the structure of JavaScript modules, you may add a .d.ts files to the root of your project including declare module 'playfab-web-sdk' to declare the ‘playfab-sdk’ module. Then you can refer to my working code:

  import { _decorator, Component, Node, log} from 'cc';
     const { ccclass, property } = _decorator;
        
     import pf from 'playfab-sdk';
        
     const PlayFab= pf.PlayFab  as PlayFabModule.IPlayFab;
     const clientApis=pf.PlayFabClient as PlayFabClientModule.IPlayFabClient;
        
     let titleData={
         titleId:"xxxx"
     };
        
     @ccclass('Test')
     export class Test extends Component {
         start() {
                 PlayFab.settings.titleId=titleData.titleId;
        
                 const loginRequest={
                     CustomId: "test",
                     CreateAccount: true
                 };
                 const loginCallback=(error:PlayFabModule.IPlayFabError,result:PlayFabModule.IPlayFabSuccessContainer<PlayFabClientModels.LoginResult>): void =>{
                     if(error!=null){
                         log("login failure");
                     }else{
                         log(result.data.PlayFabId);
                     }
                 };
                 clientApis.LoginWithCustomID(loginRequest,loginCallback);
         }
        
         update(deltaTime: number) {
                
         }
     }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.