Commit 82e98919 authored by Tt's avatar Tt

动画逻辑分离

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