Commit a1aa324b authored by limingzhe's avatar limingzhe

fix: 拖拽异常

parent 81415e7d
{"ver":"1.1.2","uuid":"1689616d-6621-4fdf-87ec-126ceba30dc8","isBundle":false,"bundleName":"","priority":1,"compressionType":{},"optimizeHotUpdate":{},"inlineSpriteFrames":{},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}} {
\ No newline at end of file "ver": "1.1.2",
"uuid": "1689616d-6621-4fdf-87ec-126ceba30dc8",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {
"ios": false,
"android": false
},
"subMetas": {}
}
\ No newline at end of file
...@@ -5,9 +5,9 @@ function RemoteResourceCounter(count, cb) { ...@@ -5,9 +5,9 @@ function RemoteResourceCounter(count, cb) {
this.currentLoadedResourceCount = 0; this.currentLoadedResourceCount = 0;
this.finishCallback = cb; this.finishCallback = cb;
} }
RemoteResourceCounter.prototype.load = function(num) { RemoteResourceCounter.prototype.load = function (num) {
this.currentLoadedResourceCount += num; this.currentLoadedResourceCount += num;
console.log('RemoteResourceCounter', this.remoteResourceCount , this.currentLoadedResourceCount); console.log('RemoteResourceCounter', this.remoteResourceCount, this.currentLoadedResourceCount);
if (this.remoteResourceCount <= this.currentLoadedResourceCount) { if (this.remoteResourceCount <= this.currentLoadedResourceCount) {
this.finishCallback && this.finishCallback(); this.finishCallback && this.finishCallback();
} }
...@@ -22,78 +22,78 @@ cc.Class({ ...@@ -22,78 +22,78 @@ cc.Class({
properties: { properties: {
videoplayer: { videoplayer: {
// ATTRIBUTES: // ATTRIBUTES:
default: null, // The default value will be used only when the component attaching default: null, // The default value will be used only when the component attaching
// to a node for the first time // to a node for the first time
type: cc.VideoPlayer, // optional, default is typeof default type: cc.VideoPlayer, // optional, default is typeof default
}, },
cat: { cat: {
// ATTRIBUTES: // ATTRIBUTES:
default: null, // The default value will be used only when the component attaching default: null, // The default value will be used only when the component attaching
// to a node for the first time // to a node for the first time
type: cc.Node, // optional, default is typeof default type: cc.Node, // optional, default is typeof default
}, },
toggleButton: { toggleButton: {
// ATTRIBUTES: // ATTRIBUTES:
default: null, // The default value will be used only when the component attaching default: null, // The default value will be used only when the component attaching
// to a node for the first time // to a node for the first time
type: cc.Node, // optional, default is typeof default type: cc.Node, // optional, default is typeof default
}, },
toggleButtonSprite: { toggleButtonSprite: {
// ATTRIBUTES: // ATTRIBUTES:
default: null, // The default value will be used only when the component attaching default: null, // The default value will be used only when the component attaching
// to a node for the first time // to a node for the first time
type: cc.Node, // optional, default is typeof default type: cc.Node, // optional, default is typeof default
}, },
loadingSprite: { loadingSprite: {
// ATTRIBUTES: // ATTRIBUTES:
default: null, // The default value will be used only when the component attaching default: null, // The default value will be used only when the component attaching
// to a node for the first time // to a node for the first time
type: cc.Node, // optional, default is typeof default type: cc.Node, // optional, default is typeof default
}, },
beginAudioClip: cc.AudioClip, beginAudioClip: cc.AudioClip,
finishAudioClip: cc.AudioClip, finishAudioClip: cc.AudioClip,
hintAudioClip: cc.AudioClip, hintAudioClip: cc.AudioClip,
playStatus: { playStatus: {
default: null, default: null,
type: cc.SpriteFrame, type: cc.SpriteFrame,
}, },
pauseStatus: { pauseStatus: {
default: null, default: null,
type: cc.SpriteFrame, type: cc.SpriteFrame,
}, },
m1: { m1: {
default: null, default: null,
type: cc.Sprite, type: cc.Sprite,
}, },
m2: { m2: {
default: null, default: null,
type: cc.Sprite, type: cc.Sprite,
}, },
durationLabel: { durationLabel: {
default: null, default: null,
type: cc.Label type: cc.Label
}, },
currentTimeLabel: { currentTimeLabel: {
default: null, default: null,
type: cc.Label type: cc.Label
}, },
barTag: { barTag: {
default: null, default: null,
type: cc.Node type: cc.Node
}, },
ProgressBar: { ProgressBar: {
default: null, default: null,
type: cc.ProgressBar type: cc.ProgressBar
}, },
qupeiyinBtn: { qupeiyinBtn: {
default: null, default: null,
type: cc.Sprite type: cc.Sprite
}, },
hintBtn: { hintBtn: {
default: null, default: null,
type: cc.Button type: cc.Button
} }
}, },
...@@ -103,35 +103,35 @@ cc.Class({ ...@@ -103,35 +103,35 @@ cc.Class({
this.initSceneData(); this.initSceneData();
this.initSize(); this.initSize();
this._armatureDisPlay = this.cat.getComponent(dragonBones.ArmatureDisplay); this._armatureDisPlay = this.cat.getComponent(dragonBones.ArmatureDisplay);
//获取 Armatrue //获取 Armatrue
this._armature = this._armatureDisPlay.armature(); this._armature = this._armatureDisPlay.armature();
this._isReadyToPlay = false; this._isReadyToPlay = false;
this.toggleButtonSpriteNode = this.toggleButtonSprite.getComponent(cc.Sprite); this.toggleButtonSpriteNode = this.toggleButtonSprite.getComponent(cc.Sprite);
this.setButtonPlayStatus(TOGGLE_BUTTON_STATUS.PAUSE); this.setButtonPlayStatus(TOGGLE_BUTTON_STATUS.PAUSE);
}, },
onDestroy() { onDestroy() {
this.isPlayMusicAnimation = false; this.isPlayMusicAnimation = false;
cc.audioEngine.stop(this.beginAudioID ); cc.audioEngine.stop(this.beginAudioID);
cc.audioEngine.stop(this.finishAudioID ); cc.audioEngine.stop(this.finishAudioID);
cc.audioEngine.stop(this.hintAudioID ); cc.audioEngine.stop(this.hintAudioID);
this.isDestroy = true; this.isDestroy = true;
if (this.hideControlId) { if (this.hideControlId) {
clearTimeout(this.hideControlId); clearTimeout(this.hideControlId);
} }
if (this.videoPlayer) { if (this.videoPlayer) {
this.videoplayer.pause(); this.videoplayer.pause();
} }
}, },
ctor() { ctor() {
this.beginPlayed = false; this.beginPlayed = false;
this.finishPlayed = false; this.finishPlayed = false;
this.gameStatus = new RemoteResourceCounter(0, this.hideRabbit.bind(this)) this.gameStatus = new RemoteResourceCounter(0, this.hideRabbit.bind(this))
}, },
...@@ -146,7 +146,7 @@ cc.Class({ ...@@ -146,7 +146,7 @@ cc.Class({
onCompleted(player) { onCompleted(player) {
console.log('onCompleted'); console.log('onCompleted');
// this.videoStatus.isVideoPlaying = false; // this.videoStatus.isVideoPlaying = false;
if (this.hideControlId) { if (this.hideControlId) {
clearTimeout(this.hideControlId); clearTimeout(this.hideControlId);
} }
...@@ -171,13 +171,13 @@ cc.Class({ ...@@ -171,13 +171,13 @@ cc.Class({
} }
this.finishPlayed = true; this.finishPlayed = true;
} else { } else {
this._armatureDisPlay.playAnimation('normal', 0); this._armatureDisPlay.playAnimation('normal', 0);
if (window && window.courseware && window.courseware.nextPage) { if (window && window.courseware && window.courseware.nextPage) {
console.log('call window.courseware.nextPage'); console.log('call window.courseware.nextPage');
// window.courseware.nextPage(); // window.courseware.nextPage();
} }
} }
// this.videoplayer.currentTime = 0 ; // this.videoplayer.currentTime = 0 ;
// this.ProgressBar.progress = 0; // this.ProgressBar.progress = 0;
...@@ -199,7 +199,7 @@ cc.Class({ ...@@ -199,7 +199,7 @@ cc.Class({
this.gameStatus.load(1); this.gameStatus.load(1);
} }
}, },
hideRabbit() { hideRabbit() {
// console.log('hideRabbit'); // console.log('hideRabbit');
...@@ -212,7 +212,7 @@ cc.Class({ ...@@ -212,7 +212,7 @@ cc.Class({
// } else { // } else {
// this.playGame(); // this.playGame();
// } // }
}, },
playGame() { playGame() {
console.log('playGame'); console.log('playGame');
...@@ -233,7 +233,7 @@ cc.Class({ ...@@ -233,7 +233,7 @@ cc.Class({
} }
}, },
playMusicAnimation(){ playMusicAnimation() {
this.isPlayMusicAnimation = true; this.isPlayMusicAnimation = true;
const op1 = this.m1.node.position const op1 = this.m1.node.position
const op2 = this.m2.node.position const op2 = this.m2.node.position
...@@ -248,32 +248,32 @@ cc.Class({ ...@@ -248,32 +248,32 @@ cc.Class({
const dur1 = this.randRange(0.5, 1.2) const dur1 = this.randRange(0.5, 1.2)
const dur2 = this.randRange(0.5, 1.2) const dur2 = this.randRange(0.5, 1.2)
cc.tween(sprNode) cc.tween(sprNode)
.to(dur1, pos1, { easing: 'cubicOut' }) .to(dur1, pos1, { easing: 'cubicOut' })
.to(dur2, pos2, { easing: 'cubicIn' }) .to(dur2, pos2, { easing: 'cubicIn' })
.call(() => { .call(() => {
// console.log('anim play ends'); // console.log('anim play ends');
fn(sprNode, op); fn(sprNode, op);
}) })
.start(); .start();
} }
fn(this.m1.node, op1); fn(this.m1.node, op1);
fn(this.m2.node, op2); fn(this.m2.node, op2);
}, },
stopMusicAnimation(){ stopMusicAnimation() {
this.isPlayMusicAnimation = false; this.isPlayMusicAnimation = false;
}, },
randRange(a, b) { randRange(a, b) {
const t = [a, b].sort() const t = [a, b].sort()
let r = Math.random() * (t[1] - t[0]) let r = Math.random() * (t[1] - t[0])
if (a >= 1) { if (a >= 1) {
r = Math.random() * (t[1] - t[0] + 1) r = Math.random() * (t[1] - t[0] + 1)
} }
return r + t[0]; return r + t[0];
}, },
getRandomPosInRect(target, r) { getRandomPosInRect(target, r) {
const x = this.randRange(target.x - r, target.x + r); const x = this.randRange(target.x - r, target.x + r);
const y = this.randRange(target.y - r, target.y + r); const y = this.randRange(target.y - r, target.y + r);
return {x, y} return { x, y }
}, },
...@@ -316,6 +316,8 @@ cc.Class({ ...@@ -316,6 +316,8 @@ cc.Class({
sy = frameSize.height / this._designSize.height; sy = frameSize.height / this._designSize.height;
this._mapScaleMin = Math.min(sx, sy) * this._cocosScale; this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
this._mapScaleMax = Math.max(sx, sy) * this._cocosScale; this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;
this.canvas = cc.find("Canvas");
}, },
...@@ -335,14 +337,14 @@ cc.Class({ ...@@ -335,14 +337,14 @@ cc.Class({
this.data = JSON.parse(JSON.stringify(this.data)) this.data = JSON.parse(JSON.stringify(this.data))
this.preloadItem() this.preloadItem()
}); });
this.qupeiyinBtn.node.on(cc.Node.EventType.TOUCH_START, function() { this.qupeiyinBtn.node.on(cc.Node.EventType.TOUCH_START, function () {
console.log(123123); console.log(123123);
if (window.courseware && window.courseware.nextPage) { if (window.courseware && window.courseware.nextPage) {
window.courseware.nextPage(); window.courseware.nextPage();
} }
}, this); }, this);
this.toggleButton.on(cc.Node.EventType.TOUCH_START, function() { this.toggleButton.on(cc.Node.EventType.TOUCH_START, function () {
this.hideWolf(); this.hideWolf();
this.delayHideControl(); this.delayHideControl();
...@@ -351,67 +353,67 @@ cc.Class({ ...@@ -351,67 +353,67 @@ cc.Class({
console.log(cc.audioEngine.isMusicPlaying()); console.log(cc.audioEngine.isMusicPlaying());
if (cc.audioEngine.isMusicPlaying()) { if (cc.audioEngine.isMusicPlaying()) {
return; return;
} }
cc.audioEngine.stop(this.finishAudioID); cc.audioEngine.stop(this.finishAudioID);
if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PAUSE) { if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PAUSE) {
this.setButtonPlayStatus(true); this.setButtonPlayStatus(true);
} else { } else {
this.setButtonPlayStatus(false); this.setButtonPlayStatus(false);
} }
this._armatureDisPlay.playAnimation('normal', 0); this._armatureDisPlay.playAnimation('normal', 0);
}, this); }, this);
this.hintBtn.node.on('click', function() { this.hintBtn.node.on('click', function () {
console.log('play hint', (!cc.audioEngine.isMusicPlaying() && !this.videoplayer.isPlaying())); console.log('play hint', (!cc.audioEngine.isMusicPlaying() && !this.videoplayer.isPlaying()));
if (!cc.audioEngine.isMusicPlaying() && !this.videoplayer.isPlaying()){ if (!cc.audioEngine.isMusicPlaying() && !this.videoplayer.isPlaying()) {
this.hintAudioID = cc.audioEngine.playMusic(this.hintAudioClip, false, 1); this.hintAudioID = cc.audioEngine.playMusic(this.hintAudioClip, false, 1);
this._armatureDisPlay.playAnimation('begin', 0); this._armatureDisPlay.playAnimation('begin', 0);
cc.audioEngine.setFinishCallback(this.hintAudioID, () => { cc.audioEngine.setFinishCallback(this.hintAudioID, () => {
this._armatureDisPlay.playAnimation('normal', 0); this._armatureDisPlay.playAnimation('normal', 0);
}) })
} }
}, this); }, this);
// 设置缓冲加载动画 转动 // 设置缓冲加载动画 转动
cc.tween(this.loadingSprite) cc.tween(this.loadingSprite)
.by(0.1, { angle: -10 }) .by(0.1, { angle: -10 })
.repeatForever() .repeatForever()
.start(); .start();
// 覆盖Air中的dialogStatus方法 用于监测视频加载状态 // 覆盖Air中的dialogStatus方法 用于监测视频加载状态
if(window['air']) { if (window['air']) {
window["air"].dialogStatus = (statusCode) => { window["air"].dialogStatus = (statusCode) => {
console.log("缓冲", statusCode) console.log("缓冲", statusCode)
if(statusCode == 701) { if (statusCode == 701) {
// 缓冲中 // 缓冲中
this.loadingSprite.active = true; this.loadingSprite.active = true;
} else if(statusCode == 702) { } else if (statusCode == 702) {
// 缓冲结束 // 缓冲结束
this.loadingSprite.active = false; this.loadingSprite.active = false;
} }
} }
} }
cc.view.setResizeCallback((params) => { cc.view.setResizeCallback((params) => {
console.log('Resize', params); console.log('Resize', params);
this.initdDrag() this.initdDrag()
}); });
this.initdDrag(); this.initdDrag();
window.p = this; window.p = this;
}, },
initdDrag() { initdDrag() {
const maxX = this.ProgressBar.node.width; const maxX = this.ProgressBar.node.width;
const minX = 0; const minX = 0;
this.barTag.off(cc.Node.EventType.TOUCH_START); this.barTag.off(cc.Node.EventType.TOUCH_START);
this.barTag.on(cc.Node.EventType.TOUCH_START, (e) => { this.barTag.on(cc.Node.EventType.TOUCH_START, (e) => {
// return; // return;
if (!this.videoplayer.isPlaying()) { if (!this.videoplayer.isPlaying()) {
return return
...@@ -422,68 +424,77 @@ cc.Class({ ...@@ -422,68 +424,77 @@ cc.Class({
if (!this._isReadyToPlay) { if (!this._isReadyToPlay) {
return; return;
} }
console.log("TOUCH_START"); console.log("TOUCH_START");
// this.userDragStart = true; // this.userDragStart = true;
}); });
this.barTag.off(cc.Node.EventType.TOUCH_MOVE); this.barTag.off(cc.Node.EventType.TOUCH_MOVE);
this.barTag.on(cc.Node.EventType.TOUCH_MOVE,(e) => { this.barTag.on(cc.Node.EventType.TOUCH_MOVE, (e) => {
this.delayHideControl();
this.delayHideControl();
// if (!this.videoplayer.isPlaying() ) { // if (!this.videoplayer.isPlaying() ) {
// return; // return;
// } // }
// console.log("TOUCH_MOVE"); // console.log("TOUCH_MOVE");
var delta = e.getDelta();
let newX = this.barTag.x+delta.x; const worldPos = e.getLocation();
const localPos = this.barTag.parent.convertToNodeSpaceAR(worldPos);
newX = Math.min(maxX, Math.max(newX, minX));
this.barTag.x = newX;
const percent = newX / maxX;
let newX = localPos.x;
const dur = this.videoplayer.getDuration();
this.currentTimeLabel.string = this.formatTime(percent * dur ); // var delta = e.getDelta();
// let newX = this.barTag.x + delta.x;
newX = Math.min(maxX, Math.max(newX, minX));
this.barTag.x = newX;
const percent = newX / maxX;
const dur = this.videoplayer.getDuration();
this.currentTimeLabel.string = this.formatTime(percent * dur);
// console.log(percent * dur); // console.log(percent * dur);
this.videoplayer.currentTime = percent * dur; this.videoplayer.currentTime = percent * dur;
}); });
this.barTag.off(cc.Node.EventType.TOUCH_ENDED); this.barTag.off(cc.Node.EventType.TOUCH_ENDED);
this.barTag.on(cc.Node.EventType.TOUCH_ENDED, (e) => { this.barTag.on(cc.Node.EventType.TOUCH_ENDED, (e) => {
console.log("TOUCH_ENDED"); console.log("TOUCH_ENDED");
// this.userDragStart = false; // this.userDragStart = false;
this.updateBarByPos(this.barTag.x); this.updateBarByPos(this.barTag.x);
}); });
this.barTag.on(cc.Node.EventType.MOUSE_UP, (e) => { this.barTag.on(cc.Node.EventType.MOUSE_UP, (e) => {
console.log("MOUSE_UP"); console.log("MOUSE_UP");
// this.userDragStart = false; // this.userDragStart = false;
this.updateBarByPos(this.barTag.x); this.updateBarByPos(this.barTag.x);
}); });
// this.barTag.off(cc.Node.EventType.TOUCH_CANCEL); // this.barTag.off(cc.Node.EventType.TOUCH_CANCEL);
// this.barTag.on(cc.Node.EventType.TOUCH_CANCEL, (e) => { // this.barTag.on(cc.Node.EventType.TOUCH_CANCEL, (e) => {
// console.log("TOUCH_CANCEL"); // console.log("TOUCH_CANCEL");
// this.userDragStart = false; // this.userDragStart = false;
// this.updateBarByPos(this.barTag.x); // this.updateBarByPos(this.barTag.x);
// }); // });
// this.ProgressBar.node.off(cc.Node.EventType.TOUCH_START); // this.ProgressBar.node.off(cc.Node.EventType.TOUCH_START);
// this.ProgressBar.node.on(cc.Node.EventType.TOUCH_START, (e) => { // this.ProgressBar.node.on(cc.Node.EventType.TOUCH_START, (e) => {
// if (this.videoplayer.isPlaying()) { // if (this.videoplayer.isPlaying()) {
// const pos = e.getLocation(); // const pos = e.getLocation();
// const pPos = this.ProgressBar.node.convertToNodeSpaceAR(pos); // const pPos = this.ProgressBar.node.convertToNodeSpaceAR(pos);
// const newX = Math.min(maxX, Math.max(pPos.x, minX)); // const newX = Math.min(maxX, Math.max(pPos.x, minX));
// this.updateBarByPos(newX); // this.updateBarByPos(newX);
// } // }
// // console.log("ProgressBar TOUCH_START", newX); // // console.log("ProgressBar TOUCH_START", newX);
// }); // });
// this.node.off(cc.Node.EventType.TOUCH_START); // this.node.off(cc.Node.EventType.TOUCH_START);
// this.node.on(cc.Node.EventType.TOUCH_START, (e) => { // this.node.on(cc.Node.EventType.TOUCH_START, (e) => {
// console.log("screen TOUCH_START"); // console.log("screen TOUCH_START");
// }); // });
// const pgBar = this.ProgressBar.node; // const pgBar = this.ProgressBar.node;
}, },
getData(func) { getData(func) {
if (window && window.courseware) { if (window && window.courseware) {
window.courseware.getData(func, 'scene'); window.courseware.getData(func, 'scene');
...@@ -521,7 +532,7 @@ cc.Class({ ...@@ -521,7 +532,7 @@ cc.Class({
this.addPreloadAudio(() => { this.addPreloadAudio(() => {
this.preload(); this.preload();
}); });
cc.debug.setDisplayStats(false); cc.debug.setDisplayStats(false);
}, },
...@@ -556,7 +567,7 @@ cc.Class({ ...@@ -556,7 +567,7 @@ cc.Class({
preload() { preload() {
const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList); const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
console.log('preloadArr: ', JSON.stringify( preloadArr) ); console.log('preloadArr: ', JSON.stringify(preloadArr));
cc.assetManager.loadAny(preloadArr, null, null, (err, data) => { cc.assetManager.loadAny(preloadArr, null, null, (err, data) => {
this.videoplayer.remoteURL = this.data.video_url; this.videoplayer.remoteURL = this.data.video_url;
...@@ -569,7 +580,7 @@ cc.Class({ ...@@ -569,7 +580,7 @@ cc.Class({
} }
}); });
}, },
addServerListener() { addServerListener() {
console.log('addServerListener'); console.log('addServerListener');
...@@ -586,8 +597,8 @@ cc.Class({ ...@@ -586,8 +597,8 @@ cc.Class({
addPreloadAudio(callback) { addPreloadAudio(callback) {
this._audioResList.push({url: this.data.finish_audio_url || ''}); this._audioResList.push({ url: this.data.finish_audio_url || '' });
this._audioResList.push({url: this.data.hint_audio_url || ''}); this._audioResList.push({ url: this.data.hint_audio_url || '' });
const url1 = this.data.video_url; const url1 = this.data.video_url;
if (!url1) { if (!url1) {
...@@ -602,7 +613,7 @@ cc.Class({ ...@@ -602,7 +613,7 @@ cc.Class({
this._audioResList.push({ url: url || '' }); this._audioResList.push({ url: url || '' });
callback(); callback();
}) })
}, },
getVideoUrl(callback) { getVideoUrl(callback) {
const url1 = this.data.video_url; const url1 = this.data.video_url;
...@@ -687,7 +698,7 @@ cc.Class({ ...@@ -687,7 +698,7 @@ cc.Class({
this.controlNode = cc.find("Canvas/Controls"); this.controlNode = cc.find("Canvas/Controls");
this.wolfNode = cc.find("Canvas/catBox"); this.wolfNode = cc.find("Canvas/catBox");
this.controlNode.active = false; this.controlNode.active = false;
this.wolfNode.active = false; this.wolfNode.active = false;
}, },
...@@ -718,7 +729,7 @@ cc.Class({ ...@@ -718,7 +729,7 @@ cc.Class({
if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PLAY) { if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PLAY) {
return; return;
} }
this.toggleButtonSpriteNode.spriteFrame= this.pauseStatus; this.toggleButtonSpriteNode.spriteFrame = this.pauseStatus;
this.toggleButton.status = TOGGLE_BUTTON_STATUS.PLAY; this.toggleButton.status = TOGGLE_BUTTON_STATUS.PLAY;
this.videoplayer.play(); this.videoplayer.play();
this.playMusicAnimation(); this.playMusicAnimation();
...@@ -726,7 +737,7 @@ cc.Class({ ...@@ -726,7 +737,7 @@ cc.Class({
if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PAUSE) { if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PAUSE) {
return; return;
} }
this.toggleButtonSpriteNode.spriteFrame= this.playStatus ; this.toggleButtonSpriteNode.spriteFrame = this.playStatus;
this.toggleButton.status = TOGGLE_BUTTON_STATUS.PAUSE; this.toggleButton.status = TOGGLE_BUTTON_STATUS.PAUSE;
this.videoplayer.pause(); this.videoplayer.pause();
this.stopMusicAnimation(); this.stopMusicAnimation();
...@@ -736,73 +747,73 @@ cc.Class({ ...@@ -736,73 +747,73 @@ cc.Class({
return !!this.toggleButton.status; return !!this.toggleButton.status;
}, },
updateBarByPos(newX) { updateBarByPos(newX) {
const maxX = this.ProgressBar.node.width; const maxX = this.ProgressBar.node.width;
const minX = 0; const minX = 0;
const percent = newX / maxX; const percent = newX / maxX;
if (percent > 1) { if (percent > 1) {
percent = 1 percent = 1
} }
this.ProgressBar.progress = percent; this.ProgressBar.progress = percent;
const dur = this.videoplayer.getDuration(); const dur = this.videoplayer.getDuration();
console.log('updateBarByPos',percent * dur); console.log('updateBarByPos', percent * dur);
this.videoplayer.currentTime = percent * dur this.videoplayer.currentTime = percent * dur
}, },
updateBarByTime(ct){ updateBarByTime(ct) {
this.currentTimeLabel.string = this.formatTime(ct); this.currentTimeLabel.string = this.formatTime(ct);
const dur = this.videoplayer.getDuration(); const dur = this.videoplayer.getDuration();
let percent = ct / dur; let percent = ct / dur;
if (percent > 1) { if (percent > 1) {
percent = 1 percent = 1
} }
this.ProgressBar.progress = percent; this.ProgressBar.progress = percent;
const maxX = this.ProgressBar.node.width; const maxX = this.ProgressBar.node.width;
const minX = 0; const minX = 0;
let newX = percent * maxX; let newX = percent * maxX;
newX = Math.min(maxX, Math.max(newX, minX)); newX = Math.min(maxX, Math.max(newX, minX));
// console.log('updateBarByTime', newX); // console.log('updateBarByTime', newX);
this.barTag.x = newX; this.barTag.x = newX;
}, },
formatTime(time) { formatTime(time) {
if (time === undefined) { if (time === undefined) {
return ''; return '';
} }
let hh = Math.floor(time / 60 / 60); let hh = Math.floor(time / 60 / 60);
if (hh > 0) { if (hh > 0) {
hh = `${hh.toString().padStart(2, '0')}:`; hh = `${hh.toString().padStart(2, '0')}:`;
} else { } else {
hh = ''; hh = '';
} }
const mm = Math.floor(time / 60).toString().padStart(2, '0'); const mm = Math.floor(time / 60).toString().padStart(2, '0');
const ss = Math.round(time % 60).toString().padStart(2, '0'); const ss = Math.round(time % 60).toString().padStart(2, '0');
return `${hh}${mm}:${ss}`; return `${hh}${mm}:${ss}`;
}, },
update (dt) { update(dt) {
if (this.toggleButtonSpriteNode) { if (this.toggleButtonSpriteNode) {
// console.log(this.userDragStart); // console.log(this.userDragStart);
const ct = this.videoplayer.currentTime; const ct = this.videoplayer.currentTime;
if (ct) { if (ct) {
this.updateBarByTime(ct); this.updateBarByTime(ct);
} }
if (this.videoplayer.isPlaying()) { if (this.videoplayer.isPlaying()) {
if (this.toggleButton.status === TOGGLE_BUTTON_STATUS.PLAY) { if (this.toggleButton.status === TOGGLE_BUTTON_STATUS.PLAY) {
return; return;
} }
this.setButtonPlayStatus(false); this.setButtonPlayStatus(false);
} else { } else {
if (this.toggleButton.status === TOGGLE_BUTTON_STATUS.PAUSE) { if (this.toggleButton.status === TOGGLE_BUTTON_STATUS.PAUSE) {
return; return;
} }
this.setButtonPlayStatus(true); this.setButtonPlayStatus(true);
} }
} }
}, },
...@@ -888,7 +899,7 @@ cc.Class({ ...@@ -888,7 +899,7 @@ cc.Class({
this.initReplayBtn(); this.initReplayBtn();
this.initArrowBtn(); this.initArrowBtn();
}, },
initArrowBtn() { initArrowBtn() {
...@@ -909,7 +920,7 @@ cc.Class({ ...@@ -909,7 +920,7 @@ cc.Class({
initReplayBtn() { initReplayBtn() {
this.replayBtn = cc.find("Canvas/btn_replay"); this.replayBtn = cc.find("Canvas/btn_replay");
this.replayBtn.on('touchstart', () => { this.replayBtn.on('touchstart', () => {
this.hideWolf(); this.hideWolf();
this.delayHideControl(); this.delayHideControl();
...@@ -917,11 +928,11 @@ cc.Class({ ...@@ -917,11 +928,11 @@ cc.Class({
console.log(cc.audioEngine.isMusicPlaying()); console.log(cc.audioEngine.isMusicPlaying());
if (cc.audioEngine.isMusicPlaying()) { if (cc.audioEngine.isMusicPlaying()) {
return; return;
} }
cc.audioEngine.stop(this.finishAudioID); cc.audioEngine.stop(this.finishAudioID);
if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PAUSE) { if (this.toggleButton.status == TOGGLE_BUTTON_STATUS.PAUSE) {
this.setButtonPlayStatus(true); this.setButtonPlayStatus(true);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment