• CocosCreator入门之《摘星星》-完全学习记录(四)-END


    完整版:https://quqi.gblhgk.com/s/184718/ykolFXd1LYL9mzQE

    最后就是加得分特效,让画面更生动。

    先上预览:

    关于如何制作得分特效预制,以及如何制作动画和在动画编辑器中绑定响应函数,前辈已给出详尽教学——我再赘述也不及的:

    https://blog.csdn.net/la_vie_est_belle/article/details/102652568

    关于插件推荐,再重复推荐一次论坛大神@Next的作品:https://blog.csdn.net/la_vie_est_belle/article/details/102652568

    这是正常项目的实时节点显示,可以看到star一直是那一个,socreFX出现又消失:

    当有些地方出错时(比如动画编辑器最后一帧忘记或者写错回调函数):

    插曲:

    最后贴上思路和代码:

      这里仅仅是添加得分特效模块需要新增的代码,不能够直接运行:

      

     1 // ScoreAnim.js
     2 
     3 cc.Class({
     4   extends: cc.Component,
     5 
     6   init(scoreFX) {
     7     this.scoreFX = scoreFX;
     8   },
     9 
    10   hide() {
    11     this.scoreFX.despawn();
    12   }
    13 });
     1 // ScoreFX.js
     2 
     3 cc.Class({
     4   extends: cc.Component,
     5 
     6   properties: {
     7       anim: {
     8         default: null,
     9         type: cc.Animation
    10       }
    11   },
    12 
    13   init (game) {
    14     this.game = game;
    15     let scoreAnim = this.anim.getComponent('ScoreAnim');
    16     scoreAnim.init(this);
    17   },
    18 
    19   despawn() {
    20     this.game.despawnScoreFX(this.node);
    21   },
    22 
    23   play() {
    24     this.anim.play('score_pop');
    25   }
    26 });
     1 // Game.js
     2 
     3 cc.Class({
     4   extends: cc.Component,
     5 
     6   properties: {
     7     scoreFXPrefab: {
     8       default: null,
     9       type: cc.Prefab
    10     },
    11   },
    12 
    13   onLoad () {
    14     this.scoreFxPool = new cc.NodePool('ScoreFX');
    15   },
    16 
    17   
    18   gainScore(pos) {
    19     let fx = this.spawnScoreFX();
    20     this.node.addChild(fx);
    21     fx.setPosition(pos);
    22 
    23     let scoreFX = fx.getComponent('ScoreFX');
    24     scoreFX.init(this);
    25     scoreFX.play();
    26   },
    27 
    28   spawnScoreFX() {
    29     let fx = this.scoreFxPool.get();
    30 
    31     if (!fx) {
    32       fx = cc.instantiate(this.scoreFXPrefab);
    33     }
    34   
    35     return fx;
    36   },
    37 
    38   despawnScoreFX(scoreFx) {
    39     this.scoreFxPool.put(scoreFx);
    40   }
    41 });

    以上,祝学习愉快。

  • 相关阅读:
    清除目录下的文件 java
    基于Android AFW实现的app多开研究
    soap方式调用webserver接口发送短信
    qt编译配置
    Redis常用命令
    vue history模式刷新页面进入404解决方案
    [PyTorch] PyTorch安装对各组件版本的要求
    SQL Server获取连接的IP地址
    Delphi中idHttpServer
    SQL Server 分页问题
  • 原文地址:https://www.cnblogs.com/ForrestCui94/p/12781177.html
Copyright © 2020-2023  润新知