小程序
小游戏
企业微信
微信支付
扫描小程序码分享
我目前是想在移动过程中想停止移动,这个有办法可以实现么?
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
不用那么复杂啊
命名一个变量playStates,用来显示播放或者暂停的状态,false为暂停,true为正在播放,控制显示播放或者暂停按钮(polyline为轨迹路线,playTime 为运动次数,通过自加来控制播放,运动完一次,自加一次,再开始下次运动)
<text class="iconfont icon-play" @click="play" v-if="!playStates"></text>
<text class="iconfont icon-pause" @click="pause" v-if="playStates"></text>
暂停按钮方法 :
pause() {
this.playStates= false;
},
播放按钮方法:
play() {
this.playStates= true;
this.run(this.polyline[0].points[this.playTime + 1])
轨迹运动方法:
run(nextPoint) {
this.mapContext.translateMarker({
markerId: 0,
destination: {
latitude: nextPoint.latitude,
longitude: nextPoint.longitude
autoRotate: false,
duration: 2000,
animationEnd: (res) => {
// 单段运动完成
if (++this.playTime < this.polyline[0].points.length - 1) {
// 如果播放次数小于路径总数,则未播放完成
if(this.playStates) {
// 如果是播放状态,就继续回调播放方法
this.play();
}
} else {
// 播放完成
console.log('播放完成')
this.playTime = 0;
fail: (err) => {
console.log('轨迹播放失败', err)
})
写得有点粗糙,看不懂再问我吧
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
文档里面还没有看到,不过你可以将想停下来的位置赋给 destination 的指定地点,相当于用变量将中间点,临时放在 指定地点.不过你要将最终的指定地点用另一个变量保存下来,不然当前的位置就是你的目的最终位置..
你试一下这个呢.
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
不用那么复杂啊
命名一个变量playStates,用来显示播放或者暂停的状态,false为暂停,true为正在播放,控制显示播放或者暂停按钮(polyline为轨迹路线,playTime 为运动次数,通过自加来控制播放,运动完一次,自加一次,再开始下次运动)
<text class="iconfont icon-play" @click="play" v-if="!playStates"></text>
<text class="iconfont icon-pause" @click="pause" v-if="playStates"></text>
暂停按钮方法 :
pause() {
this.playStates= false;
},
播放按钮方法:
play() {
this.playStates= true;
this.run(this.polyline[0].points[this.playTime + 1])
},
轨迹运动方法:
run(nextPoint) {
this.mapContext.translateMarker({
markerId: 0,
destination: {
latitude: nextPoint.latitude,
longitude: nextPoint.longitude
},
autoRotate: false,
duration: 2000,
animationEnd: (res) => {
// 单段运动完成
if (++this.playTime < this.polyline[0].points.length - 1) {
// 如果播放次数小于路径总数,则未播放完成
if(this.playStates) {
// 如果是播放状态,就继续回调播放方法
this.play();
}
} else {
// 播放完成
console.log('播放完成')
this.playTime = 0;
}
},
fail: (err) => {
console.log('轨迹播放失败', err)
}
})
},
写得有点粗糙,看不懂再问我吧
文档里面还没有看到,不过你可以将想停下来的位置赋给 destination 的指定地点,相当于用变量将中间点,临时放在 指定地点.不过你要将最终的指定地点用另一个变量保存下来,不然当前的位置就是你的目的最终位置..
你试一下这个呢.