# OnlineBattleManager.sendFrameInput(Object option)
以 Promise 风格调用:支持
# 功能描述
发送玩家操作数据,用于帧同步。发送的数据会通过 onFrame 事件广播给所有玩家。
# 参数
# Object option
| 属性 | 类型 | 默认值 | 必填 | 说明 |
| data | string | 是 | 游戏操作数据(UTF-8字符串格式) | |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
# 注意事项
- 只能在帧同步进行中调用
- 发送的数据会通过
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);
});
