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定义的成员(方法或属性),是每个类对象 ...
随机推荐
- java8模拟grouby方法
public class ListUtils{ /** * list 集合分组 * * @param list 待分组集合 * @param groupBy 分组Key算法 * @param < ...
- Nginx 解析PHP的原理 | CGI、FastCGI及php-fpm的关系
Nginx解析PHP的原理,CGI/FastCGI以及PHP-Fpm的关系. 一.PHP+Nginx应运而生的场景.随着互联网的发展,用户对此接受面广,数据流的增大使得Web端的运行承载压力日益增大, ...
- [openjudge-搜索]城堡问题(The Castle)
题目描述 描述 图1是一个城堡的地形图.请你编写一个程序,计算城堡一共有多少房间,最大的房间有多大.城堡被分割成mn(m≤50,n≤50)个方块,每个方块可以有0~4面墙. 输入 程序从标准输入设备 ...
- 6.MongoDB4.0在Windows环境的下载、安装、配置
简单来说:MongoDB4.0在Windows下已经不需要再次配置db文件夹之类操作,安装完成直接进行连接测试即可,以下是具体过程(此前网上很多的教程都已经过时) 1.下载:https://www.m ...
- vue用mand-mobile ui做交易所移动版实战示例
vue用mand-mobile ui做交易所移动版实战示例 先展示几个界面: 目录结构: main.js // The Vue build version to load with the `impo ...
- introduce myself
大家好啊,我是来自计算机一班的喻达龙,是2018届的萌新一个,很高兴与大家相约在这里.我想,大家都是怀抱相同的梦想带着一样的抱负走进涉外.我们从稚嫩蜕化为成熟,我相信我们在这里会从菜鸟变为大佬的,当然 ...
- 高度自适应不能触发transition的解决方法
1. 前言 在我们不能确定一个元素的高度的时候,要使用transition过渡,是不会触发的,比如一个p标签 内容行数不固定 我们可能就要初始 height: 0 ; 过渡到 height: au ...
- 安装Joomla!3
在日常测试中搭建一个web 站点进行进行linux 相关功能测试,只是不喜欢httpd 或者nginx 的默认界面: 安装Joomla!3: 系统:centos 7 软件: 连接: https:// ...
- 在Linux下OpenCV的下载和编译
原理上来说,和windows下没有差别,我们同样使用Cmake-GUI来解决问题. 我们推荐QT和OpenCV全部采用官方的方式重新安装一遍,否则可能会丢失一些模块,而这些都会降低开发效率. 1.参考 ...
- AJAX跨域问题以及解决思路(更新中)
跨域的三大原因(同时满足) 浏览器限制 跨域 XHR请求 解决思路: 让浏览器不做限制,指定参数,让浏览器不做校验,但该方法不太合理,它需要每个人都去做改动. 不要发出XHR请求,这样就算是跨域,浏览 ...