mobile - 在移动浏览器中滑动表格
问题描述
我和我的队友正在用 dart 为移动浏览器编写游戏“Battlecity”。问题在于在移动浏览器中滑动坦克方向(从左到右,从右到左等)。它具有很大的延迟(并且由于某种原因在 Chrome 浏览器中不起作用)。如果您在移动设备上启动游戏,您可以更好地看到问题(只需打开游戏链接:https ://javajunikorn.github.io/BattleCity/build/web/html/test.html )有趣的是,问题仅存在于游戏场上的滑动(在我们的例子中是 27*27 html 表)。如果我们退出游戏感觉,那效果会很好。
这是我们控制器的代码:
class Direction{
Point first, last;
Game game;
void startListening(){
window.onTouchStart.listen((ev) {
last = null;
first = ev.touches.first.client;
});
window.onTouchMove.listen((ev){
last = ev.touches.first.client;
});
window.onTouchEnd.listen((ev) {
if(last == null || first.distanceTo(last) < 20)
game.player.shoot();
else {
Point d = first - last;
if(d.x.abs() > d.y.abs()){
//Waagerecht
if( first.x > last.x){
//links
game.player.changeDirection(Directions.left);
}
else{
//rechts
game.player.changeDirection(Directions.right);
}
}
else{
//Senkrecht
if(first.y > last.y){
//Up
game.player.changeDirection(Directions.up);
}
else{
//Down
game.player.changeDirection(Directions.down);
}
}
}
});
window.onKeyPress.listen((k) {
//Shoot
if(k.which == 32) { //spacebar
game.player.shoot();
}
//Up
if(k.which == 119 || k.keyCode == KeyCode.UP){
game.player.changeDirection(Directions.up);
}
//Down
if(k.which == 115 || k.keyCode == KeyCode.DOWN){
game.player.changeDirection(Directions.down);
}
//Left
if(k.which == 97 || k.keyCode == KeyCode.LEFT){
game.player.changeDirection(Directions.left);
}
//Right
if(k.which == 100 || k.keyCode == KeyCode.RIGHT){
game.player.changeDirection(Directions.right);
}
});
}
}
解决方案
推荐阅读
- ios - 单个购物车文件以指定和安装多个目标的依赖项
- regex - 如何在替换的正则表达式部分将变量插入到正则表达式模式中?
- python - 使用 smtplib 接收的邮件中不包含主题
- java - Dynamo DB 对 HasKey 列表运行多个查询,但没有范围键
- android - 在 Firebase 数据库中保存 ArrayList
- python - 匹配以两位或三位数字开头但在某处不包含特定模式的事件
- r - 如何用 R 对列表中的索引进行排序?
- c# - 当前上下文中不存在名称“FileUtil”
- r - 如何在 R 中另一个数据集的列中选择一个数据集中的某些行?
- python - 如何使用双 for 循环将元素名称添加到结果中?