Commit 3ab9a267 authored by 张子元's avatar 张子元

feat:产生气泡并上移

parent 175b3d93
......@@ -20,12 +20,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadAnima() {
}
private speed: number;
async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData()
this.initView()
this.initEvent()
this.initGame()
}
initView() {
initData() {
this.speed = 30
}
initView() {}
initEvent() {
let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone')
// 底部海螺点击事件
pg.view.touchOn(bottom_megaphone, this.create_bubbles, this)
}
initGame() {
// 底部海螺
let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone')
// 开始海螺从底部升起
......@@ -36,44 +49,59 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.create_bubbles()
})
btn.start()
pg.view.touchOn(bottom_megaphone, this.create_bubbles, this)
let paoaParent = pg.view.find(this, 'layer_game/bg/paopao/bubble')
// 点击泡泡
pg.view.touchOn(paoaParent, this.touchPaoPao, this)
}
// 制造气泡
create_bubbles() {
let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone')
let newPaoPao = cc.instantiate(bottom_megaphone)
let layer_paopao = pg.view.find(this, 'layer_game/bg/layer_paopao')
let paoaoParent = pg.view.find(this, 'layer_game/bg/paopao')
let newPaoPao = cc.instantiate(paoaoParent)
let paopao = newPaoPao.getChildByName("bubble")
let broken = newPaoPao.getChildByName("bubble_broken")
let btn = cc.tween(bottom_megaphone)
layer_paopao.addChild(newPaoPao)
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(() => {
let paoaoParent = pg.view.find(this, 'layer_game/bg/paopao')
let paopao = pg.view.find(this, 'layer_game/bg/paopao/bubble')
let broken = pg.view.find(this, 'layer_game/bg/paopao/bubble_broken')
paoaoParent.x = 135
paoaoParent.y = -450
newPaoPao.x = 135
newPaoPao.y = -450
paopao.width = 70
paopao.height = 70
paoaoParent.opacity = 0
pg.view.visible(paoaoParent, true)
newPaoPao.opacity = 0
pg.view.visible(newPaoPao, true)
pg.view.visible(broken, false)
cc.tween(paoaoParent).to(0.8, {opacity: 255}).call(() => {
cc.tween(paoaoParent).to(2, {x: Math.floor(Math.random()*900), y: Math.floor(Math.random()*300), scale: 3}).start()
// 点击泡泡
pg.view.touchOn(newPaoPao, this.touchPaoPao, this)
cc.tween(newPaoPao).to(0.8, {opacity: 255}).call(() => {
let positionY = Math.floor(Math.random()*300)
let positionX = this.getPositionX()
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()
}).start()
}
}).start()
}).start()
})
btn.start()
}
getPositionX() {
if(Math.random() < 0.5) {
return - Math.floor(Math.random()*900)
} else {
return Math.floor(Math.random()*900)
}
}
// 点击泡泡
touchPaoPao() {
touchPaoPao(e: any) {
// 成功 泡泡破碎 里面的内容消失
// 失败 泡泡左右微晃两次
let fail = pg.view.find(this, 'layer_game/bg/paopao/bubble')
let fail = e.target
let btn = cc.tween(fail)
btn.to(0.1, { x: -5 }).by(0.1, { x: 0 }).by(0.1, { x: 5 }).by(0.1, { x: 0 })
btn.to(0.1, { x: -5 }).by(0.1, { x: 0 }).by(0.1, { x: 5 }).by(0.1, { x: 0 })
btn.by(0.1, { x: -5 }).by(0.1, { x: 0 }).by(0.1, { x: 5 }).by(0.1, { x: 0 })
btn.by(0.1, { x: -5 }).by(0.1, { x: 0 }).by(0.1, { x: 5 }).by(0.1, { x: 0 })
btn.start()
}
}
......
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