简体   繁体   English

iPad / Android平板电脑上的HTML5 Canvas(游戏)

[英]HTML5 Canvas (game) on iPad / Android tablets

While attempting to make a game using Canvas I noticed a few quirks on tablet / phone browsers. 在尝试使用Canvas制作游戏时,我注意到平板电脑/手机浏览器上有一些怪癖。

1) How do I disable the Canvas from being selectable? 1)如何禁用Canvas可选? It seems like when the user touches it, it highlights the canvas, and almost makes an attempt to select it. 看起来当用户触摸它时,它突出显示画布,并且几乎尝试选择它。 This is undesired. 这是不希望的。

2) Browser slide gestures. 2)浏览器滑动手势。 Some browser have slide gestures that override any movement capturing done in the canvas or webpage. 某些浏览器具有滑动手势,可覆盖在画布或网页中完成的任何移动捕获。 This is extremely annoying and undesired as well. 这非常令人讨厌并且也是不受欢迎的。

3) Canvas control with HTML UI elements. 3)使用HTML UI元素进行画布控制。 I noticed when there is a canvas present with fellow ui elements (such as text) sometimes clicking or dragging in the canvas will highlight a part of the HTML and instead drags the HTML elements instead of hitting the canvas. 我注意到当画布存在其他ui元素(例如文本)时,有时在画布中单击或拖动会突出显示HTML的一部分,而是拖动HTML元素而不是点击画布。

Any help is greatly appreciated! 任何帮助是极大的赞赏! I was hoping HTML5 would be mature enough to allow for good compatibility on mobile as well as desktop. 我希望HTML5足够成熟,以便在移动设备和桌面设备上实现良好的兼容性。 The idea is to be able to code once and play everywhere....thanks! 这个想法是能够编码一次并在任何地方播放....谢谢!

This should fix your issues relating to #1 and #3: 这应该可以解决与#1和#3相关的问题:

canvas.addEventListener('selectstart', function(e) { e.preventDefault(); return false; }, false);

#2 seems like an awfully separate question, but I've never had a problem with slide gestures overriding any of my canvas stuff. #2看起来像是一个非常独立的问题,但我从来没有遇到滑动手势覆盖任何画布的问题。 Try using e.preventDefault(); 尝试使用e.preventDefault(); at the beginning of your touch events. 在触摸事件开始时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM