cocos2d-x js 中创建node的方法
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 namevar 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.FontDefinitionvar 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 namevar 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的方法的更多相关文章
- js中创建数组的方法
1.声明或创建一个不指定长度的数组(Array)的方式为: 如:var arrayObj = new Array(); 2.声明或创建一个数组并指定长度的数组(Array)的方式为: 如:var ar ...
- node.js中的url.parse方法使用说明
node.js中的url.parse方法使用说明:https://blog.csdn.net/swimming_in_it_/article/details/77439975 版权声明:本文为博主原创 ...
- js中创建html标签、加入select下默认的option的value和text、删除select元素节点下全部的OPTION节点
<pre name="code" class="java"> jsp 中的下拉框标签: <s:select name="sjx&qu ...
- Angular JS 中的服务注册方法
在Angular JS中创建服务的几种方法 factory() service() constant() value() provider() factory(name,fn(){}) 该服务为单例的 ...
- node.js中的fs.rename()方法
node.js 中的fs.rename()模块 var fs=require('fs');//node.js的核心模块 原生模块.修改文件名称,可更改文件的存放路径 方法说明 : 修改文件名称,可更改 ...
- JS中定义类的方法
JS中定义类的方式有很多种: 1.工厂方式 function Car(){ var ocar = new Object; ocar.color = "blue" ...
- js中this和回调方法循环-我们到底能走多远系列(35)
我们到底能走多远系列(35) 扯淡: 13年最后一个月了,你们在13年初的计划实现了吗?还来得及吗? 请加油~ 主题: 最近一直在写js,遇到了几个问题,可能初入门的时候都会遇到吧,总结下. 例子: ...
- JS中令人发指的valueOf方法介绍
彭老湿近期月报里提到了valueOf方法,兴致来了翻了下ECMA5里关于valueOf方法的介绍,如下: 15.2.4.4 Object.prototype.valueOf ( ) When the ...
- JS中定义类的方法<转>
转载地址:http://blog.csdn.net/sdlfx/article/details/1842218 PS(个人理解): 1) 类通过prototype定义的成员(方法或属性),是每个类对象 ...
随机推荐
- Python之多进程&异步并行
由于python的gil,多线程不是cpu密集型最好的选择 多进程可以完全独立的进程环境中运行程序,可以充分的利用多处理器 但是进程本身的隔离带来的数据不共享也是一个问题,而且线程比进程轻量 impo ...
- (转载)关于管理计算机\\xp1 找不到网络路径的解决方案
关于管理计算机\\xp1 找不到网络路径的解决方案 使用域管理员登录域控DC,然后打开AD用户和计算机 选择一台域成员计算机,然后选择管理,结果出现如下提示:点击确定后出现如下提示随后,立刻用域管理员 ...
- centos7.5 修改网卡名称
1.修改网卡配置文件中名称信息 vim /etc/sysconfig/network-scripts/ifcfg-ens33 将其中的名称为ens33的改为eth0 ,并将uuid删除以便后面克隆 2 ...
- python locust 性能测试:locsut参数化-保证并发测试数据唯一性,不循环取数据
from locust import TaskSet, task, HttpLocustimport queue class UserBehavior(TaskSet): @task def test ...
- mysql日志介绍
1. 错误日志 错误日志记录的事件: a. 服务器启动关闭过程中的信息 b. 服务器运行过程中的错误信息 c. 事件调试器运行一个事件时间生的信息 d. 在从服务器上启动从服务器进程时产生的信息 2. ...
- firefox 实现web交互机器人
现在仅有火狐浏览器可以这样操作 -- Filefox 下面是项目目录 -- 前端页面 -- html <!DOCTYPE html> <html lang="en" ...
- oracel数据库主键自增
-- Create sequence create sequence FILE_ID_SEQ 主键名(自增列) minvalue 1 起始 maxvalue 99999 最 ...
- Java内存模型学习笔记
Java内存模型(JMM):描述了java程序中各种变量(线程共享变量)的范根规则,以及在JVM中将变量存储到内存和从内存中读取出变量这样的底层细节.共享变量就是指一个线程中的变量在其他线程中也是可见 ...
- Qt::WindowFlags枚举类型解析
在使用Qt设计的时候经常会看到QWidget控件的构造函数出现下面这样一句话: QWidget(QWidget *parent=0,Qt::WindowFlags f=0) QWidget *pare ...
- Docker Kubernetes Volume 网络数据卷
Docker Kubernetes Volume 网络数据卷 由于支持网络数据卷众多 今天只拿nfs作为案例. 支持网络数据卷 nfs iscsi glusterfs awsElasticBlockS ...