0

我使用 HTML5 网络套接字对象移动发送,然后我使用 Uint8Array 转换此值。问题是我在移动对象时得到的值在进行转换后得到的值是双倍的,我得到了浮点值。这是示例:初始值:

player_x:633.8823529411765
player_y:412.235294117647



_stringConvertToUint8Array:function (strData) {  
    // View the byte buffer as an array of 8-bit unsigned integers
    var arrData = new Uint8Array(strData.length);
    for (var i=0;i<strData.length;++i) {
        arrData[i] = strData.charCodeAt(i);
    }
    // Log the binary array
    cc.log("SEND ARRAY BUFFER: " + arrData.buffer);
    return arrData;
},
sendMassage: function(reqJson)
{
    if (this.m_wsiSendBinary.readyState == WebSocket.OPEN)
    {

        var buf = Encode(reqJson);
        var binary = this._stringConvertToUint8Array(buf);
        this.m_wsiSendBinary.send(binary.buffer);
    }
    else
    {
        var warningStr = "send binary websocket instance wasn't ready...";

        }
    },

打印结果

SEND ARRAY BUFFER: [object ArrayBuffer]
Websockts.js?_t=1469105183221:30 {   
    "player_y": 412.235294,
    "player_x": 633.882353
}
4

0 回答 0