# OnlineBattleManager.sendFrameInput(Object option)

以 Promise 风格调用:支持

# 功能描述

发送玩家操作数据,用于帧同步。发送的数据会通过 onFrame 事件广播给所有玩家。

# 参数

# Object option

属性类型默认值必填说明
datastring游戏操作数据(UTF-8字符串格式)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

# 注意事项

  • 只能在帧同步进行中调用
  • 发送的数据会通过 onFrame 事件广播给所有玩家
  • 建议使用JSON格式的字符串传递复杂数据

# 示例代码

let tapOnlineBattle = tap.getOnlineBattleManager();

// 回调风格
tapOnlineBattle.sendFrameInput({
  data: "hello from mini game",
  success: (res) => {
    console.log('发送输入成功');
  },
  fail: ({errMsg, errno}) => {
    console.error('发送输入失败:', errMsg);
  }
});

// 发送JSON格式的复杂数据
tapOnlineBattle.sendFrameInput({
  data: JSON.stringify({
    action: 'move',
    x: 100,
    y: 200
  }),
  success: (res) => {
    console.log('发送输入成功');
  }
});

// Promise风格
tapOnlineBattle.sendFrameInput({
  data: "hello from mini game"
}).then(res => {
  console.log('发送输入成功');
}).catch(error => {
  console.error('发送输入失败:', error);
});