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. Select input 两个元素的宽度高度跟设定值不一致的问题

    在做登录框的时候,需要一个select 元素作为账号输入,一个input作为密码输入框.在css 文件中,将这两个元素的position 设置为relative ,并且width 设置为100%.刷新 ...

  2. python 匿名函数捕获变量值 (执行时的值)

  3. linux中make的有关规则的特性

    我过去认为 makefile 只是一种将一组组的 shell 命令列出来的简便方法:过了一段时间我了解到它们是有多么的强大.灵活以及功能齐全.这篇文章带你领略其中一些有关规则的特性. 规则 规则是指示 ...

  4. poj2115 C Looooops(exgcd)

    poj2115 C Looooops 题意: 对于C的for(i=A ; i!=B ;i +=C)循环语句,问在k位存储系统中循环几次才会结束. 若在有限次内结束,则输出循环次数. 否则输出死循环. ...

  5. Html table、thead、tr、th、td 标签

    Html table.thead.tr.th.td 标签 案例一 <!-- table 表格标签,配置表格使用.border="1" 添加表格框架 --> <ta ...

  6. oracle addm报告

    可通过@?/rdbms/admin/addmrpt.sql生成ADDM报告 ADDM本身并不是很实用,抽象级别太高,用于初步判断系统配置/IO子系统是否合理和快速参考,一个报告截图如下: 任务 '任务 ...

  7. rabbitmq安装与高可用集群配置

    rabbitmq版本:3.6.12 rabbitmq安装 1.安装openssl wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz &a ...

  8. freeswqitch odbc

    1.安装驱动 yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel -y yum install mysql-conn ...

  9. Springboot学习笔记(一)-线程池的简化及使用

    工作中经常涉及异步任务,通常是使用多线程技术,比如线程池ThreadPoolExecutor,它的执行规则如下: 在Springboot中对其进行了简化处理,只需要配置一个类型为java.util.c ...

  10. 使用VS Code调试Node

    1.双击打开vscode 2.找到底层面板 把ctrl改成LF 2. 3.打开文件夹,建立项目test 4.新建hellow.js 输入: var name='world'; var s='hello ...