pixelstream-cn
Version:
基于虚幻引擎的像素流平台
50 lines (45 loc) • 1.35 kB
JavaScript
import base from "./base.js";
import messageType from "./messageType.js";
function initData(type,touches){
let data = new DataView(new ArrayBuffer(2 + 7 * touches.length));
data.setUint8(0, type);
data.setUint8(1, touches.length);
let byte = 2;
for (let t = 0; t < touches.length; t++) {
let touch = touches[t];
data.setUint16(byte, touch.coord.x, true);
byte += 2;
data.setUint16(byte, touch.coord.y, true);
byte += 2;
data.setUint8(byte, touch.finger, true);
byte += 1;
data.setUint8(byte, 255 * touch.force, true); // force is between 0.0 and 1.0 so quantize into byte.
byte += 1;
data.setUint8(byte, touch.coord.inRange ? 1 : 0, true); // mark the touch as in the player or not
byte += 1;
}
return data;
}
class start extends base{
constructor(touches){
super();
this.data = initData(messageType.TouchStart,touches);
}
}
class end extends base{
constructor(touches){
super();
this.data = initData(messageType.TouchEnd,touches);
}
}
class move extends base{
constructor(touches){
super();
this.data = initData(messageType.TouchMove,touches);
}
}
export default {
start:start,
end:end,
move:move
}