学习爆破点点小游戏
首先,我们先搭建好场景(如下图),然后新建game脚本挂载在bg节点上,接下来在game脚本中编写代码。
【截图】
- 放置玩家节点
- 放置敌人节点
- 点击发射事件
- 爆炸效果
- update判断是否撞击了
- 游戏结束,重新加载场景
1、放置玩家节点
placePlayer() {
this.playerNode.active = true; // 激活节点
this.isFire = false; // 玩家可发射标识
this.playerNode.y = -cc.winSize.height / 4;
// 玩家的下移动画
let dua = 10;
this.playerAction = cc.tween(this.playerNode)
.to(dua, {
position: cc.v2(0, -(cc.winSize.height / 2 - this.playerNode.height))})
.call(() => {
// 碰到下面的尖刺,游戏结束
this.die();
})
.start()
}
2、放置敌人
placeEnemy() {
this.enemyNode.active = true; // 激活节点
// 敌人初始位置
this