1、精灵Sprite 一共4种创建方式

(1) 根据图片资源路径创建

1
2
3
4
//参数1:图片资源路径
var sprite1 = cc.Sprite.create("res/zifeiyu.png");
//参数1:图片资源路径,参数2:显示区域
var sprite2 = cc.Sprite.create("res/zifeiyu.png",cc.rect(0,0,480,320));

(2) 根据plist文件中的frame name创建. 注意:必须要在前头加#符号作为区分

1
2
//参数1:帧名字 frame name
var sprite = cc.Sprite.create('#zifeiyu.png');

(3) 根据sprite frame创建

1
2
3
var spriteFrame = cc.spriteFrameCache.getSpriteFrame("zifeiyu.png");
//参数1:cc.SpriteFrame对象
var sprite = cc.Sprite.create(spriteFrame);

(4) 根据纹理texture创建

1
2
3
4
5
var texture = cc.textureCache.addImage("zifeiyu.png");
//参数1:纹理
var sprite1 = cc.Sprite.create(texture);
//参数1:纹理,参数2:显示区域
var sprite2 = cc.Sprite.create(texture, cc.rect(0,0,480,320));

2、文字LabelTTF 一共2种创建方式

(1) 根据字体、大小等多参数创建

1
2
//参数1:显示字符串,参数2:字体,参数3:字号,参数4:宽高,参数5:定位
var myLabel = cc.LabelTTF.create('label text''Times New Roman', 32, cc.size(320,32), cc.TEXT_ALIGNMENT_LEFT);

(2) 根据自定义对象cc.FontDefinition创建

1
2
3
4
5
var fontDef = new cc.FontDefinition();
fontDef.fontName = "Arial";
fontDef.fontSize = "32";
//参数1:显示字符串,参数2:自定义对象cc.FontDefinition
var myLabel = cc.LabelTTF.create('label text', fontDef);

3、动画Animation一共3种创建方式

(1) 空创建

1
2
//无参数
var animation1 = cc.Animation.create();

(2) 根据精灵帧(sprite frames)创建

1
2
3
4
5
6
7
8
9
var spriteFrameArr = [];
var spriteFrame = cache.getSpriteFrame("ipastimes.png");
spriteFrameArr.push(spriteFrame);
//参数1:精灵帧数组
var animation1 = cc.Animation.create(spriteFrameArr);
//参数1:精灵帧数组,参数2:延续时间,单位为秒
var animation2 = cc.Animation.create(spriteFrameArr, 0.2);
//参数1:精灵帧数组,参数2:延续时间,单位为秒,参数3:循环次数
var animation3 = cc.Animation.create(spriteFrameArr, 0.2,2);

(3) 根据动作帧(animation frames)创建

1
2
3
4
5
6
7
8
9
10
var animationFrameArr = [];
var animationFrame = new cc.AnimationFrame();
aFrame1.initWithSpriteFrame(spriteFrame1,0.5);
animationFrameArr.push(animationFrame);
//参数1:动画帧数组
var animation1 = cc.Animation.create(animationFrameArr);
//参数1:动画帧数组,参数2:延续时间,单位为秒
var animation2 = cc.Animation.create(animationFrameArr, 0.2);
//参数1:动画帧数组,参数2:延续时间,单位为秒,参数3:循环次数
var animation3 = cc.Animation.create(animationFrameArr, 0.2,2);

4、批量SpriteBatchNode一共2种创建方式

(1)根据图片资源路径

1
2
//参数1:图片路径,参数2:容量
var spriteBatchNode = cc.SpriteBatchNode.create("res/animations/ipastimes.png", 50);

(2)根据纹理

1
2
3
var texture = cc.textureCache.addImage("res/animations/ipastimes.png");
//参数1:纹理,参数2:容量
var spriteBatchNode = cc.SpriteBatchNode.create(texture,50);

5、精灵SpriteFrame一共2种创建方式

(1)根据图片资源路径

1
2
3
4
//参数1:图片路径,参数2:区域
var frame1 = cc.SpriteFrame.create("res/ipastimes.png",cc.rect(0,0,90,128));
//参数1:图片路径,参数2:区域,参数3:是否旋转,参数4:偏移量,参数5:原区域
var frame2 = cc.SpriteFrame.create("res/ipastimes.png",cc.rect(0,0,90,128),false,0,cc.size(90,128));

(2)根据纹理

1
2
3
4
5
var texture = cc.textureCache.addImage("res/ipastimes.png");
//参数1:图片路径,参数2:区域
var frame1 = cc.SpriteFrame.create(texture, cc.rect(0,0,90,128));
//参数1:图片路径,参数2:区域,参数3:是否旋转,参数4:偏移量,参数5:原区域
var frame2 = cc.SpriteFrame.create(texture, cc.rect(0,0,90,128),false,0,cc.size(90,128));

6、粒子效果ParticleSystem一共2种创建方式

(1)根据图片资源路径

1
2
//参数1:粒子数量
var particle = cc.ParticleSystem.create(50);

(2)根据纹理

1
2
//参数1:粒子工具particleDesigner导出的文件
var particle = cc.ParticleSystem.create("res/particle.plist");

7、物理PhysicsSprite 一共4种创建方式

(1) 根据图片资源路径创建

1
2
3
4
//参数1:图片资源路径
var physicsSprite1 = cc.PhysicsSprite.create("res/ipastimes.png");
//参数1:图片资源路径,参数2:显示区域
var physicsSprite2 = cc.PhysicsSprite.create("res/ipastimes.png",cc.rect(0,0,480,320));

(2) 根据plist文件中的frame name创建. 注意:必须要在前头加#符号作为区分

1
2
//参数1:帧名字 frame name
var physicsSprite = cc.PhysicsSprite.create('#ipastimes.png');

(3) 根据sprite frame创建

1
2
3
var spriteFrame = cc.spriteFrameCache.getSpriteFrame("ipastimes.png");
//参数1:cc.SpriteFrame对象
var physicsSprite = cc.PhysicsSprite.create(spriteFrame);

(4) 根据纹理texture创建

1
2
3
4
5
var texture = cc.textureCache.addImage("ipastimes.png");
//参数1:纹理
var physicsSprite1 = cc.PhysicsSprite.create(texture);
//参数1:纹理,参数2:显示区域
var physicsSprite2 = cc.PhysicsSprite.create(texture, cc.rect(0,0,480,320));

8、大纹理TextureAtlas一共2种创建方式

(1)根据图片资源路径

1
2
//参数1:图片路径,参数2:容量
var textureAtlas = cc.TextureAtlas.create("res/animations/ipastimes.png", 50);

(2)根据纹理

1
2
3
var texture = cc.textureCache.addImage("res/animations/ipastimes.png");
//参数1:纹理,参数2:容量
var textureAtlas = cc.TextureAtlas.create(texture,50);

 

源引:http://blog.csdn.net/tonny_guan/article/details/44624863

cocos2d-x js 中创建node的方法的更多相关文章

  1. js中创建数组的方法

    1.声明或创建一个不指定长度的数组(Array)的方式为: 如:var arrayObj = new Array(); 2.声明或创建一个数组并指定长度的数组(Array)的方式为: 如:var ar ...

  2. node.js中的url.parse方法使用说明

    node.js中的url.parse方法使用说明:https://blog.csdn.net/swimming_in_it_/article/details/77439975 版权声明:本文为博主原创 ...

  3. js中创建html标签、加入select下默认的option的value和text、删除select元素节点下全部的OPTION节点

    <pre name="code" class="java"> jsp 中的下拉框标签: <s:select name="sjx&qu ...

  4. Angular JS 中的服务注册方法

    在Angular JS中创建服务的几种方法 factory() service() constant() value() provider() factory(name,fn(){}) 该服务为单例的 ...

  5. node.js中的fs.rename()方法

    node.js 中的fs.rename()模块 var fs=require('fs');//node.js的核心模块 原生模块.修改文件名称,可更改文件的存放路径 方法说明 : 修改文件名称,可更改 ...

  6. JS中定义类的方法

    JS中定义类的方式有很多种: 1.工厂方式    function Car(){     var ocar = new Object;     ocar.color = "blue" ...

  7. js中this和回调方法循环-我们到底能走多远系列(35)

    我们到底能走多远系列(35) 扯淡: 13年最后一个月了,你们在13年初的计划实现了吗?还来得及吗? 请加油~ 主题: 最近一直在写js,遇到了几个问题,可能初入门的时候都会遇到吧,总结下. 例子: ...

  8. JS中令人发指的valueOf方法介绍

    彭老湿近期月报里提到了valueOf方法,兴致来了翻了下ECMA5里关于valueOf方法的介绍,如下: 15.2.4.4 Object.prototype.valueOf ( ) When the ...

  9. JS中定义类的方法<转>

    转载地址:http://blog.csdn.net/sdlfx/article/details/1842218 PS(个人理解): 1) 类通过prototype定义的成员(方法或属性),是每个类对象 ...

随机推荐

  1. window中普通用户无法登录远程桌面

    解决方案就是将该用户加到 Remote Desktop Users 这个用户组中. 使用命令 net localgroup "Remote Desktop Users" 用户名 / ...

  2. Pycharm激活方法步骤

    Pycharm激活步骤 第一步:找到hosts文件 先按下键盘的win + r ,然后复制c:\windows\system32\drivers\etc粘贴到对话框回车打开文件管理器 第二步:修改ho ...

  3. Bubble Sort (找规律)

    通过模拟之后我们发现对于每一个位置上的数他都有一个规律,那就是先左移然后在右移.然后仔细发现可以知道,先右移的距离是前面比该数大的个数.右移就直接右移到目标位置了.然后用一个树状数组从左到右边扫边加就 ...

  4. thymeleaf 添加语法提示

    thymeleaf 添加语法提示: xmlns:th="http://www.thymeleaf.org"

  5. 线程同步——lock锁

    线程同步即解决线程安全问题的第三种方式——使用lock锁 代码实现: 其中,ReentrantLock是lock接口的实现类,这边是使用多态创建,访问成员方法时,编译看左,运行看右: Reentran ...

  6. vue axios使用form-data的形式提交数据的问题

    vue axios使用form-data的形式提交数据vue axios request payload form data由于axios默认发送数据时,数据格式是Request Payload,而并 ...

  7. servlet injection analysis

    一. Spring不能通过注解向Servlet中注入实例的原理 想了解此问题的原理,就要了解tomcat启动后 servlet和spring的加载顺讯. 1.  tomcat启动后先加载web.xml ...

  8. Vue基础进阶 之 实例方法--生命周期

    在上一篇博客中我们知道生命周期的方法: 生命周期: vm.$mount:手动挂载Vue实例: vm.$destroy:销毁Vue实例,清理数据绑定,移除事件监听: vm.$nextTick:将方法中的 ...

  9. linux下对qt编写的程序进行部署

    当我们完成程序设计之后,需要将可执行程序交付客户,而运行环境里面可能是没有相关支持库的,这个时候就涉及到部署的相关问题.对于我们在Linux下基于QT编写的图像处理程序,我们采用linuxdeploy ...

  10. 剑指offer(27)字符串的排列

    题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入描述:输入 ...