我正在寻找创建一个函数,使用requestAnimationFrame和delta time在HTML5画布上滚动图像元素x像素.我无法弄清楚的是当requestAnimationFrame allready用一个参数(一个DOMHighResTimeStamp)回调我的函数时,如何为我的函数添加更多参数.我很确定以下代码不起作用:
function scroll(timestamp, distanceToScroll, secondsToScroll) {
//delta = how many milliseconds have passed between this and last draw
if (!lastDraw) {var lastDraw = timestamp;};
delta = (0.5 + (timestamp - lastDraw)) << 0; //bitwise hack for rounding integers
lastDraw = timestamp;
//speed (pixels per millisecond) = amount of pixels to move / length of animation (in milliseconds)
speed = distanceToScroll / secondsToScroll;
//new position = current position + (speed * delta)
position += (speed * delta);
context.drawImage(myImage,0,position,50,50/*of 200*/,0,0,100,100); …
Run Code Online (Sandbox Code Playgroud) 我做了使用基本的聊天应用程序node.js
,express
和socket.io
。与socket.io 的教程聊天应用程序没有太大区别,它只是在连接的客户端之间发出事件。当我在服务器上的端口3001上运行它时,它工作正常。
然后,我制作了一个代理服务器应用程序,使用node-http-proxy
该服务器侦听端口80并将基于请求的url的流量重定向到我在不同端口上运行的各种独立节点应用程序。非常简单。但是有些东西坏了。每当有人断开连接时,每个单个插座都会断开并重新连接。这对具有基于连接事件的聊天应用程序不利。客户端控制台均显示:
WebSocket与“ ws:// [某些套接字信息] ”的连接失败:在收到握手响应之前,连接已关闭
我认为这是代码的重要部分。
var http = require('http');
var httpProxy = require('http-proxy');
//create proxy template object with websockets enabled
var proxy = httpProxy.createProxyServer({ws: true});
//check the header on request and return the appropriate port to proxy to
function sites (req) {
//webapps get their own dedicated port
if (req == 'mychatwebsite.com') {return 'http://localhost:3001';}
else if (req == 'someothersite.com') {return 'http://localhost:3002';}
//static sites are …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个使用分层画布和精灵图像的基于浏览器的游戏,出于视觉和性能原因,我想默认禁用imageSmoothingEnabled.我的理解是imageSmoothingEnabled并非在所有浏览器中都可用,但有供应商前缀版本.我试图在我的所有画布(尽可能多的浏览器中)中找到一种优雅的方法来禁用此属性.到目前为止,这是我的方法:
context1.imageSmoothingEnabled = false;
context1.mozImageSmoothingEnabled = false;
context1.oImageSmoothingEnabled = false;
context1.webkitImageSmoothingEnabled = false;
context2.imageSmoothingEnabled = false;
context2.mozImageSmoothingEnabled = false;
context2.oImageSmoothingEnabled = false;
context2.webkitImageSmoothingEnabled = false;
context3.imageSmoothingEnabled = false;
context3.mozImageSmoothingEnabled = false;
context3.oImageSmoothingEnabled = false;
context3.webkitImageSmoothingEnabled = false;
//etc...
Run Code Online (Sandbox Code Playgroud)
有更优雅的方法吗?在实际创建每个画布上下文之前,是否可以将上下文的API更改为默认值为false?