判断是否继承

cc.isChildClassOf = function (subclass, superclass) {

获取所有super classes

CCClass.getInheritanceChain = function (klass) 

cc.js下有很多判断方法

判断是否是数字

cc.js.isNumber

字符串

cc.js.isString
copy all properties from arguments[1...n] to obj
cc.js.mixin

阻止事件向下层传递

event.stopPropagation();停止事件冒泡。

对node执行scheduleUpdate方法

var node = new cc.Node();
node.parent = this.node;
node.update = function (dt){
}.bind(this);
cc.director.getScheduler().scheduleUpdate(node, , false);

注意webGL 的 cc.director.getScheduler().scheduleUpdate的第4个参数可以传递function ,但在canvas中第四个参数无效

继承自cc.Asset的类

cc.TextAsset
cc.AnimationClip
cc.Font
cc.Prefab
cc.SceneAsset
cc.Script
cc.SpriteAtlas
cc.TiledMapAsset
dragonBones.DragonBonesAsset
dragonBones.DragonBonesAtlasAsset
sp.SkeletonData
cc.SpriteFrame

cc.loader.getRes  加载Sprite:如果加载过(cc.loader.loadResArr      cc.loader.loadResDir   cc.loader.loadRes等方法)此素材,可以正常读取     cc.SpriteFrame,否则会返回空

 cc.loader.loadResArray(["imgage/common/btn_common_close1.png"], cc.SpriteFrame, function () {//第一次加载(异步)
var asset = cc.loader.getRes("imgage/common/btn_common_close1.png", cc.SpriteFrame);//第二次可以用getRes加载(同步)
if (asset) {
      var node = new cc.Node();
var spr = node.addComponent(cc.Sprite);
spr.spriteFrame = asset;
       node.parent = this.node;
       node.setPosition(, );
}
}.bind(this));

如果想第一次用同步方法加载:

var node = new cc.Node();
var component = node.addComponent(cc.Sprite);
component.spriteFrame = new cc.SpriteFrame(cc.url.raw("resources/imgage/common/btn_common_close1.png"));
node.parent = this.node;
node.setPosition(0, 0);

bitmapFont  Label可以直接使用cc.loader.getRes加载,而不必担心是否加载过

 var asset = cc.loader.getRes(url, cc.Font);
if (asset) {
var node = new cc.Node();
var component = node.addComponent(cc.Label);
component.font = asset;
}

但是ttf 字体的cc.Font 只有使用cc.loader.loadRes(cc.loader.load    loadResArray   loadResDir等方法加载无效)异步加载过一次后,才能使用getRes方法直接加载

cc.AudioClip可以直接使用cc.loader.getRes同步加载

var asset = this.getRes("sound/audio_test", cc.AudioClip);
if (asset) {
var node = new cc.Node();
node.parent = this.node;
var component = node.addComponent(cc.AudioSource);
component.clip = asset;
component.play();
}

或者

  var node = new cc.Node();
node.parent = rootNode;
var component = node.addComponent(cc.AudioSource);
component.clip = cc.url.raw("resources/sound/audio_test.mp3");
component.play();

游戏增量更新后需要重新加载 cc.game.restart();

cocosCreator 支持es6新方法

1 方法的不定数量传参:

  

var func = function(arg1, ...argsArr) {
console.log("arg1:" + arg1);
for (var i = , len = argsArr.length; i < len; i ++) {
console.log("args " + i + ": " + argsArr[i]);
}
};
func(, "haha", , );

结果:

arg1:
args : haha
args :
args :

2 解构赋值

var func = function() {
return [, ];
}
var a = null;
var b = null;
[a, b] = func();
console.log("a:" + a);
console.log("b:" + b);

a 、b被分别赋值 1、 2,可以用更少的代码,实现函数返回值赋值多个变量

3 map和set的数据结构

var m = new Map([['Michael', ], ['Bob', ], ['Tracy', ]]);
m.get('Michael'); //

  map初始化

var m = new Map(); // 空Map
m.set('Adam', ); // 添加新的key-value
m.set('Bob', );
m.has('Adam'); // 是否存在key 'Adam': true
m.get('Adam'); //
m.delete('Adam'); // 删除key 'Adam'
m.get('Adam'); // undefined

  set

var s1 = new Set(); // 空Set
var s2 = new Set([, , ]); // 含1, 2, 3

  添加元素

>>> s.add()
>>> s
{, , , }
>>> s.add()
>>> s
{, , , }
for (let i of s.values()) {
  console.log(i);
}
let arr = [...s];
console.log(JSON.stringify(arr));
>>>[1, 2, 3, 4]
还有 delete() clear() forEach() keys() values() size 等方法

set 交集并集计算

let set1 = new Set([,,,,,]);
let set2 = new Set([,,,,,]); //并集
let union = new Set([...set1,...set2]);
console.log("union:" + JSON.stringify([...union]));
//[1,2,3,4,5,6,7,8,9]
//交集
let intersect = new Set([...set1].filter(x => set2.has(x)));
console.log("intersect:" + JSON.stringify([...intersect]));
//[4,5,6]
//差集
let diffsect = new Set([...set1].filter(x => !set2.has(x)));
console.log("diffsect:" + JSON.stringify([...diffsect]));
//[1,2,3]

4promise

var promise1 = new Promise(function (resolve, reject) {
GameCtr.resCtr.getSpriteAsyn(Res.sheep_plist, function (asset) {
if (asset) {
resolve(asset);
}
}, "sheep_run_0");
});
var promise2 = new Promise(function (resolve, reject) {
GameCtr.resCtr.getSpriteAsyn(Res.sheep_plist, function (asset) {
if (asset) {
resolve(asset);
}
}, "sheep_run_0");
});
Promise.all([promise1, promise2]).then(function (assets) {
for (var i = , len = assets.length; i < len; i ++) {
let asset = assets[i];
asset.position = cc.p(, i * );
asset.parent = this.node;
var atlas = asset['Atlas'];
var spr = asset.getComponent(cc.Sprite);
spr.spriteFrame = atlas.getSpriteFrames()[];
}
}.bind(this));

5 proxey

如果节点不存在自动生成节点的Tree

 function Tree() {
return new Proxy({}, handler);
}
var handler = {
get: function (target, key, receiver) {
if (!(key in target)) {
target[key] = Tree(); // 自动创建一个子树
}
return Reflect.get(target, key, receiver);
}
};
var tree = Tree();
//tree.a.b.c ="1";
console.log(tree.a.b.c);

扩展已有方法

this.testFunc = function(key) {
console.log(`testFunc1 ${key}`);
};
var obj = new Proxy(this, {
get(target, key, proxy) {
return function(...args) {
console.log(`testFunc2 ${args[]}`);
return Reflect.apply(target[key], target, args);
}
}
});
obj.testFunc(""); >>>testFunc2
>>>testFunc1

revocable proxy

this. testProxyFunc = function (key) {
console.log(`testProxyFunc ${key}`);
};
var handler = {
get(target, key, proxy) {
return function(...args) {
console.log(`testProxyFunc ${args[]}`);
return Reflect.apply(target[key], target, args);
}
}
};
var revocable = Proxy.revocable(this, handler);
var proxy = revocable.proxy;
proxy.testProxyFunc("");
revocable.revoke();
console.log("-------");
proxy.testProxyFunc(""); >>>testProxyFunc
>>>testProxyFunc
>>>-------
Uncaught TypeError: Cannot perform 'get' on a proxy that has been revoked

6 class module

    

coocsCreator杂记的更多相关文章

  1. [Erlang 0118] Erlang 杂记 V

       我在知乎回答问题不多,这个问题: "对你职业生涯帮助最大的习惯是什么?它是如何帮助你的?",我还是主动回答了一下.    做笔记 一开始笔记软件做的不好的时候就发邮件给自己, ...

  2. Ubuntu杂记——Ubuntu下用虚拟机共享上网

    由于最近把自己电脑环境换成了Ubuntu,但学校的网络是电信的闪讯,大学里用过的人都知道这货有多坑,而且没有Linux客户端,上网都是问题,怪不得国内用Linux的人那么少,特别是高校的学生(让我瞎逼 ...

  3. 一个ubuntu phper的自我修养(杂记)

    ubuntu使用杂记 1.flatabulous安装使用. flatabulous是一个ubuntu图标主题. 使用它,必须得安装tweak插件. sudo add-apt-repository pp ...

  4. 有关Java的日期处理的一些杂记

    在企业应用开发中,经常会遇到日期的相关处理,说实话JDK自带的日期方法很难用.就我个人而言我一般都会采用joda-time来替代JDK自身的日期. 这篇文章是杂记,所以写的比较零散,希望大家不要见怪. ...

  5. 分布式系统之CAP理论杂记[转]

    分布式系统之CAP理论杂记 http://www.cnblogs.com/highriver/archive/2011/09/15/2176833.html 分布式系统的CAP理论: 理论首先把分布式 ...

  6. Redis杂记

    参考资料: Redis 教程 | 菜鸟教程 : http://www.runoob.com/redis/redis-tutorial.html Redis快速入门 :http://www.yiibai ...

  7. MySQL杂记

    参考资料: w3school  SQL 教程 : http://www.w3school.com.cn/sql/index.asp 21分钟 MySQL 入门教程 : http://www.cnblo ...

  8. Android之开发杂记(一)

    1.cygwin环境变量设置 可在Cygwin.bat 中设置 set NDK_ROOT=P:/android/android-ndk-r8e 或者在home\Administrator\.bash_ ...

  9. ios程序开发杂记

    ios程序开发杂记 一.程序构建 与一般的程序构建无太大区别,都是源文件编译链接这一套,通常是在mac上做交叉编译,也就是利用xcode里带的ios编译工具集去生成arm架构的ios程序(或是x86的 ...

随机推荐

  1. json数组转java对象

    <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>ison-lib</art ...

  2. 【pyspider】关于匹配html的数据

    今天刚刚接触pyspider,在调试的时候注意匹配数据可以这样写: <div class="download-wp">         <a data-app-i ...

  3. 高级测试岗位面试题---MARK

    直接手写一个python类 直接手写一个构造函数 紧接着上面的代码,直接手写,补充完整代码,要求对列表中的人进行排序,并筛选出分数大于80的人的名单,组成一个新的列表显示出来. class Perso ...

  4. TOJ4127: Root of String

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4127 4127: Root of ...

  5. WdatePicker控件中日期的范围选择

    1.开始日期不能大于结束日期,结束日期只能选择今天之前(不包括今天) <asp:TextBox ID="T_CREATION_DATE_Start" Width=" ...

  6. 微信小程序——过滤器的模拟

    >> 编写wxs文件——filter.wxs //1. 价格格式化 function getPriceFormat(value) { return parseFloat(isNaN(val ...

  7. 修改bootstrap-table中的分页样式

    使用bootstrap-table时,使用$("")选择器没办法选中下方的分页button按钮,可能跟它是动态生成的有关吧. 最终找到与之对应的js(bootstrap-table ...

  8. 动态替换iframe的src及动态改变iframe的高度

    实现效果:点击左侧右侧内容变化,但左侧保持不变(如折叠等) 动态替换iframe的src <iframe width="100%" frameBorder="0&q ...

  9. Validate常用校验

    1.首先将jQuery.js和jquery.validate.js加入对应的页面中,如果要中文的提示语还要把messages_zh.js加入,以及对应的css文件. <link href=&qu ...

  10. WEB框架之Django实现分页功能

    一 Paginator分页器 1 首先在数据库中生成大量数据 def index(request) book_list = [] for i in rang(1000) book = Book(tit ...