作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个简单的游戏。
我有一架直升机,用户可以上下飞行。
我已经有了实现此操作的基本代码,工作正常(触摸启动+按住直升机上升,松开直升机下降)。然而,它非常“ react ”;如果你想让直升机沿直线飞行,你需要快速点击屏幕,但是无论你点击的速度有多快,直升机都会移动相当多的距离。
我需要一种方法让运动在开始上升和开始下降时变得轻松,这样直升机就可以在需要时沿相当直线飞行。
我的代码如下:
var speed = 1;
function copter_touchstart(){
clearInterval(fall);
fly = setInterval( start_fly, 2);
}
function copter_touchend(){
clearInterval(fly);
fall = setInterval( start_fall, 2);
}
function start_fly(){
var matrix = $helicopter.css('-webkit-transform').replace(/[^0-9\-.,]/g, '').split(',');
var y = matrix[5];
var new_top = parseInt(y) - speed;
$helicopter.css('-webkit-transform', 'translate3d(0, '+ new_top +'px, 0)')
}
function start_fall(){
var matrix = $helicopter.css('-webkit-transform').replace(/[^0-9\-.,]/g, '').split(',');
var y = matrix[5];
var new_top = parseInt(y) + speed;
$helicopter.css('-webkit-transform', 'translate3d(0, '+ new_top +'px, 0)')
}
$body.on('touchstart', copter_touchstart).on('touchend', copter_touchend);
JS fiddle :HERE
(触摸更改为鼠标事件)反复点击屏幕来“悬停”方 block ,太 react 了,但我不想在正常飞行时降低速度
最佳答案
过渡移动有不同类型,默认为线性。看看这里:
.object {
position: absolute;
transition: all 2s ease-in-out;
-webkit-transition: all 2s ease-in-out; /** Chrome & Safari **/
-moz-transition: all 2s ease-in-out; /** Firefox **/
-o-transition: all 2s ease-in-out; /** Opera **/
}
关于javascript - jQuery游戏-让直升机飞行更流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22399796/
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 5 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!