cocos creator从零开发2048(10)-重新开始游戏

Canvas节点下新建Sprite (单色)并重命名为btnRestart,Position设置为280和402,Size设置为150x60,Color设置为#A69A91,挂载Button组件并设置Transation属性为Scale、Zoom Scale属性为1.1。

btnRestart1

btnRestart2

btnRestart节点下新建Label (文字),String输入重新开始,Font Size和Line Height都设置为30。

编辑scripts/Game.ts,修改init方法,添加点击重新开始按钮的逻辑。

this.showScore()

const btnRestart = this.node.getChildByName('btnRestart')
btnRestart.on('click', () => cc.game.restart())
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!