Commit 82e98919 authored by Tt's avatar Tt

动画逻辑分离

parent ea2c7a4e
......@@ -68,40 +68,55 @@ export default class SceneComponent extends MyCocosSceneComponent {
return this.data.questions[this.current];
}
// 制造气泡
create_bubbles() {
async create_bubbles() {
if (this.touchNumber > this.currentQuestion.options.length) {
console.log('此题结束')
} else {
let bottom_megaphone = pg.view.find(this, 'layer_game/bottom_megaphone')
let layer_paopao = pg.view.find(this, 'layer_game/layer_paopao')
let paoaoParent = pg.view.find(this, 'layer_game/paopao')
// 创建泡泡
let newPaoPao = cc.instantiate(paoaoParent)
layer_paopao.addChild(newPaoPao)
this.updatePaoPao(newPaoPao, this.currentQuestion.options[this.touchNumber - 1]);
let btn = cc.tween(bottom_megaphone)
btn.to(0.1, { x: -5 }).to(0.1, { x: 0 }).to(0.1, { x: 5 }).to(0.1, { x: 0 })
btn.to(0.1, { x: -5 }).to(0.1, { x: 0 }).to(0.1, { x: 5 }).to(0.1, { x: 0 })
.call(() => {
newPaoPao.x = 135
newPaoPao.y = -450
newPaoPao.opacity = 0
pg.view.visible(newPaoPao, true)
cc.tween(newPaoPao).to(0.8, { opacity: 255 }).call(() => {
// 做动画
this.aniShake(bottom_megaphone).then(() => {
this.aniPaoPaoFly(newPaoPao).then(() => {
// 泡泡自行销毁
newPaoPao.parent = null;
})
})
}
this.touchNumber++;
}
aniPaoPaoFly(item) {
return new Promise((resolve, reject) => {
pg.view.visible(item, true)
item.x = 135
item.y = -450
item.opacity = 0
let positionY = Math.floor(Math.random() * 300)
let positionX = this.getPositionX()
cc.tween(item).to(0.8, { opacity: 255 })
.call(() => {
this.targetPosition = positionY
cc.tween(newPaoPao).to(positionY / this.speed, { x: positionX, y: positionY, scale: 3 }).call(() => {
if (newPaoPao.y < cc.winSize.height + 105) {
cc.tween(newPaoPao).to((750 - newPaoPao.y) / this.speed, { y: cc.winSize.height + 105 }).call(() => {
newPaoPao.destroy()
})
.to(positionY / this.speed, { x: positionX, y: positionY, scale: 3 })
.to((750 - item.y) / this.speed, { y: cc.winSize.height + 105 })
.call(() => {
resolve('');
}).start()
});
}
aniShake(item) {
return new Promise((resolve, reject) => {
cc.tween(item)
.to(0.1, { x: -5 }).to(0.1, { x: 0 }).to(0.1, { x: 5 }).to(0.1, { x: 0 })
.to(0.1, { x: -5 }).to(0.1, { x: 0 }).to(0.1, { x: 5 }).to(0.1, { x: 0 })
.call(() => {
resolve('');
}).start()
}).start()
})
btn.start()
}
this.touchNumber++;
});
}
updatePaoPao(item, data) {
let paopao = item.getChildByName("bubble")
......
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