CocosCreator引擎修改js源代码
来源:互联网 发布:java类的定义 编辑:程序博客网 时间:2024/06/06 05:42
有个需求是使用道具让卡牌停止跳着移动,而卡牌可以翻转。持续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);//继续
- CocosCreator引擎修改js源代码
- CocosCreator修改图标
- CocosCreator引擎卡在进度条进不去
- CocosCreator
- CocosCreator
- CocosCreator + 场景->节点->组件=JS脚本
- CocosCreator js 读取json,设置回调
- CocosCreator js 全局变量声明 require方式
- 使用CocosCreator进行Cocos2d-JS开发之第一弹
- cocosCreator-js客户端+pomelo服务端搭建聊天系统
- js写注册表修改IE设置(源代码)
- Unity 引擎源代码
- js引擎
- js引擎
- JS引擎
- Js引擎
- JS引擎
- JS 源代码
- 关于tableView和cell的小知识点总结
- MySQL内连接、左连接、右连接、全连接
- 10.24 25模拟
- 故事的开始
- Unity3D面试题整合
- CocosCreator引擎修改js源代码
- 《JavaScript标准参考教程(alpha)》读书笔记一:面向对象编程
- 创建云主机与availability zone的关系
- SQL 从一个表更新另一个表
- Hadoop Hive sql语法详解3--DML 操作:元数据存储
- highcharts和highstock实时刷新折线图小总结
- js课程笔记(三)BOM,事件,物体移动信息,this问题
- 算法交易VWAP&TWAP
- 面向对象设计原则 面向对象设计原则之开闭原则