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定义的成员(方法或属性),是每个类对象 ...
随机推荐
- Session, Token and SSO 有什么区别
Session, Token and SSO 有什么区别 Basic Compareation Session-based Authentication In Session-based Authen ...
- sed command
https://blog.csdn.net/solaraceboy/article/details/79272344
- is 和 == 以及 编码和解码
1.is 比较的是内存地址 a="name" b="snow" print(a is b) # False id() 获取内存地址 a=" == ...
- SSM项目思路整合NEW
#首先进行项目思路整体分析,具体包括哪些模块,如何实现等: 一)搭建环境 1.导包: (Spring核心包4个 + 面向切面的包4个 + SpringJDBC和事务的包各一个, SpringMVC两个 ...
- Spring Data Solr入门
如何将Solr的应用集成到Spring中? SpringDataSolr就是为了方便Solr的开发所研制的一个框架,其底层是对SolrJ的封装. SpringDataSolr入门小Demo 首先目录结 ...
- MVC输出缓存(OutputCache参数详解)
版权声明:本文为博主原创文章,未经博主允许转载随意. https://blog.csdn.net/kebi007/article/details/59199115 1.学习之前你应该知道这些 几乎每个 ...
- Link-Cut-Tree详解
图片参考YangZhe的论文,FlashHu大佬的博客 Link-Cut-Tree实际靠的是实链剖分,重链剖分和长链剖分珂以参考树链剖分详解 Link-Cut-Tree将某一个儿子的连边划分为实边,而 ...
- 解决eclipse修改后台代码ctrl+s总是【自动重启服务器】问题
每次修改后台代码保存总是自启动服务很是耗时,以下设置可以解决你的烦恼: 双击你要设置的项目: 点击ok,最后ctrl+s一下就搞定了. 这时候你随便修改后台代码随便ctrl+s都不会重新启动服务器.b ...
- PHP快速排序(递归)
日常的排序算法中,快速排序是其中一种.实现起来相对简单. 假设有一个数组,有若干(N)个元素(数字且无序),需要对其进行从小到大的排序. 快速排序的思路是怎么样的呢? 取一个中间值,然后,用其他数组元 ...
- [c/c++] programming之路(18)、动态分配内存malloc
一.图解堆栈 #include<stdio.h> #include<stdlib.h> #include<Windows.h> void main0(){ **]; ...