CocosCreator引擎修改js源代码

最近在用CocosCreator引擎做项目, 有个需求是一个卡牌同时执行两个动作,一个repearForever的跳着向前移动,还有一个卡牌翻转的动作。

有个需求是使用道具让卡牌停止跳着移动,而卡牌可以翻转。持续5s后,卡牌继续跳着向前。

试了一些方法,也百度了一些方法,并看了源码,没找到合适的引擎自带方法。

有说stopActionBrTag(TAG);然后重新runAction()该动作的,但实际并不是想要的效果,比如牌刚好跳在最高点时,再次runAction()的时候,会从最高点开始运动。

如果纪录position的话,会瞬移,而且有其他动作也在改变positoin的话,控制起来会很困难。

于是改了下源代码。

其中运行到真机时的c++代码和js-bindings代码已经写好(具体步骤在我的另一篇文章:http://blog.csdn.net/u010536615/article/details/52932454)。

发现在网页上调用时提示找不到该方法,于是发现CocosCreator在网页上运行和真机上运行用的是两套代码。

这里以我的需求为例子,说下怎么修改CocosCreator在网页上运行时的源代码。我用的是mac版的CocoCreator,Windows版的请找到对应目录及文件。

----1.应用程序->CocosCreator->右击->显示包内容->Contents/Resources/engine/bin/cocos2d-js-for-preview.js

----2.cc.Aciton类中添加变量(大概文件13954行):

            ctor: function() {
                this.originalTarget = null;
                this.target = null;
                this.tag = cc.Action.TAG_INVALID;
               
this.evanFlag = false;//新增evanFlag变量
            },

----3.cc.Aciton类中添加方法(我加在了setTag()方法之后,大概文件13997行):

            setEvanFlag:function (_evanFlag) {
                this.evanFlag = _evanFlag;
            },

----4.cc.ActionManager类中修改update()方法(大概文件21090行):

                            if (locCurrTarget.currentAction.evanFlag) {
                                continue;
                            }

修改后update方法为:

update: function(dt) {
                var locTargets = this._arrayTargets, locCurrTarget;
                for (var elt = 0; elt < locTargets.length; elt++) {
                    this._currentTarget = locTargets[elt];
                    locCurrTarget = this._currentTarget;
                    if (!locCurrTarget.paused) {
                        for (locCurrTarget.actionIndex = 0; locCurrTarget.actionIndex < (locCurrTarget.actions ? locCurrTarget.actions.length : 0); locCurrTarget.actionIndex++) {
                            locCurrTarget.currentAction = locCurrTarget.actions[locCurrTarget.actionIndex];
                            if (!locCurrTarget.currentAction) {
                                continue;
                            }
                            locCurrTarget.currentActionSalvaged = false;
                            //evanFlag
                            if (locCurrTarget.currentAction.evanFlag) {
                                continue;
                            }
                            locCurrTarget.currentAction.step(dt * (locCurrTarget.currentAction._speedMethod ? locCurrTarget.currentAction._speed : 1));
                            if (locCurrTarget.currentActionSalvaged) {
                                locCurrTarget.currentAction = null;
                            } else {
                                if (locCurrTarget.currentAction.isDone()) {
                                    locCurrTarget.currentAction.stop();
                                    var action = locCurrTarget.currentAction;
                                    locCurrTarget.currentAction = null;
                                    this.removeAction(action);
                                }
                            }
                            locCurrTarget.currentAction = null;
                        }
                    }
                    this._currentTargetSalvaged && 0 === locCurrTarget.actions.length && this._deleteHashElement(locCurrTarget) && elt--;
                }
            }

----5.调用:

        var action = cc.director.getActionManager().getActionByTag(9, this.node);
        action.setEvanFlag(true);//暂停

        action.setEvanFlag(true);//继续


Cocos Creator是一款流行的游戏开发引擎,它拥有丰富的功能和强大的性能,适用于各种类型的游戏开发。城建游戏是一种非常受欢迎的游戏类型,它允许玩家建设和管理自己的城市。 Cocos Creator城建源码是基于Cocos Creator引擎开发的城建游戏的源代码。这个源码提供了一个完整的城市建设游戏的基础框架,包含了各种功能和模块,如建筑物的放置和升级、资源的收集和管理、任务系统、UI设计等。 通过使用这个城建源码,开发者可以快速搭建一个城建游戏的基本框架,并在此基础上进行自定义和扩展。源码提供了各种常用的城建游戏功能的实现方法和示例,开发者可以根据自己的需求进行修改和优化。 Cocos Creator城建源码的设计和实现通常遵循一些常见的游戏开发原则,如组件化设计、面向对象编程、事件驱动等。这些原则使得源码的结构清晰、可扩展性强,开发者可以根据自己的实际情况进行修改和扩展。 使用Cocos Creator城建源码可以大大加快城建游戏的开发过程,减少开发的时间和成本。同时,Cocos Creator也提供了丰富的文档和社区支持,开发者可以在开发过程中获得帮助和解决问题。 总之,Cocos Creator城建源码是一个可以帮助开发者快速搭建城建游戏的基础框架,它提供了丰富的功能和示例,开发者可以根据自己的需求进行修改和扩展。使用这个源码可以加快游戏开发的速度,并且可以通过Cocos Creator强大的性能和功能来提升游戏的质量。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值