tt.createMoreGamesButton

2020-02-15 02:15 更新
基礎(chǔ)庫 1.23.0 開始支持本方法,低版本需做兼容處理。

創(chuàng)建更多游戲按鈕。用戶點(diǎn)擊該按鈕后,會彈出一個(gè)固定樣式的彈窗,彈窗中包含預(yù)先配置的小游戲列表。


參數(shù)

Object 類型,屬性如下:

屬性類型默認(rèn)值必填描述
typestring按鈕的類型,取值 image 或 text。image 對應(yīng)圖片按鈕,text 對應(yīng)文本按鈕
imagestring按鈕的背景圖片,type 為 image 時(shí)必填。僅支持本地圖片,目錄包括代碼包目錄、臨時(shí)文件目錄和本地用戶目錄
textstring更多游戲按鈕上的文本內(nèi)容, type 為 text 時(shí)有效
styleobject按鈕的樣式
appLaunchOptionsArray<object>小游戲的啟動參數(shù)
onNavigateToMiniGamefunction跳轉(zhuǎn)小游戲時(shí)的回調(diào)函數(shù)

appLaunchOptions 參數(shù)說明

Array<object> 類型,結(jié)構(gòu)如下:

屬性類型默認(rèn)值必填說明
appIdstring要打開的小游戲 appId
querystring查詢字符串,必須是 key1=val1&key2=val2 的格式。可通過 tt.getLaunchOptionSync() 或 tt.onShow() 獲取啟動參數(shù)中的 query
extraDataobject需要傳遞給目標(biāo)小游戲的數(shù)據(jù)??赏ㄟ^ tt.getLaunchOptionsSync() 或 tt.onShow() 返回的 referrerInfo 字段獲取對應(yīng)數(shù)據(jù)

onNavigateToMiniGame 回調(diào)函數(shù)參數(shù)

Object 類型,屬性如下:

屬性類型說明
errCodenumber跳轉(zhuǎn)錯(cuò)誤碼
errMsgstring跳轉(zhuǎn)失敗時(shí)的提示信息

errCode 取值說明

說明
0跳轉(zhuǎn)成功
1跳轉(zhuǎn)失敗
2用戶取消

style 參數(shù)說明

屬性類型默認(rèn)值必填說明
leftnumber左上角橫坐標(biāo)
topnumber左上角縱坐標(biāo)
widthnumber寬度
heightnumber高度
backgroundColorstring背景顏色
borderColorstring邊框顏色
borderWidthnumber邊框?qū)挾?/td>
borderRadiusnumber邊框圓角
textAlignstring文本的水平居中方式
fontSizenumber字號
lineHeightnumber文本的行高
textColorstring文本顏色

style.textAlign 屬性合法值

說明
left居左
center居中
right居右


返回

返回一個(gè) MoreGamesButton 對象


示例

const btn = tt.createMoreGamesButton({
  type: "image",
  image: "images/more_games_btn.png",
  style: {
    left: 20,
    top: 40,
    width: 150,
    height: 40,
    lineHeight: 40,
    backgroundColor: "#ff0000",
    textColor: "#ffffff",
    textAlign: "center",
    fontSize: 16,
    borderRadius: 4,
    borderWidth: 1,
    borderColor: "#ff0000"
  },
  appLaunchOptions: [
    {
      appId: "ttXXXXXX",
      query: "foo=bar&baz=qux",
      extraData: {}
    }
    // {...}
  ],
  onNavigateToMiniGame(res) {
    console.log("跳轉(zhuǎn)其他小游戲", res);
  }
});

btn.onTap(() => {
  console.log("點(diǎn)擊更多游戲");
});


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號