Cocos Creator脚本开发事例
HelloWorld.js
window.Global = {
gint: 168,
};
cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, World!'
},
// use this for initialization
onLoad: function () {
this.label.string = this.text;
},
// called every frame
update: function (dt) {
},
});
HelloWorld.js
SayHello.js
var helloWorld = require("HelloWorld");
cc.Class({
extends: cc.Component,
properties: {
userID: {
default: 20,
displayName: "用户ID",
tooltip: "用户的ID",
},
userName: "Foobar",
pos: new cc.Vec2(10, 20),
color: new cc.Color(255, 255, 255, 128),
any: [], // 不定义具体类型的数组
bools: [cc.Boolean],
strings: [cc.String],
floats: [cc.Float],
ints: [cc.Integer],
values: [cc.Vec2],
nodes: [cc.Node],
frames: [cc.SpriteFrame],
score: {
default: 0,
displayName: "Score (player)",
tooltip: "The score of player",
},
width: {
get: function () {
return this._width;
},
set: function (value) {
this._width = value;
}
},
player: {
default: null,
type: cc.Node
}
},
// use this for initialization
onLoad: function () {
var Shape = cc.Class({
properties: {x:1},
ctor: function () {
cc.log("Shape"); // 实例化时,父构造函数会自动调用,
},
print: function (str) { cc.log("print:" + str+" x:"+this.node.x); },
start: function () {
var node = this.node;
node.x = 100;
}
});
var shape = new Shape();
//shape.print("hello");
//shape.start();
var node = this.node;
cc.log(node);
cc.log(node.name);
cc.log(node.color);
var sprite = this.getComponent("cc.Sprite");
if(sprite!=null){
cc.log("sprite.type:"+sprite.type);
}
var label = this.getComponent("cc.Label");
if(label!=null){
cc.log("label:"+label.fontSize);
}
cc.log("this.userID:"+this.userID);
if(this.player){
var sprite2 = this.player.getComponent("cc.Sprite");
cc.log("sprite2:"+sprite2);
if(sprite2!=null){
cc.log("this.player.sprite.type:"+sprite2.type);
}
var sayHello = this.player.getComponent("SayHello");
cc.log("sayHello:"+sayHello);
if(sayHello!=null){
cc.log("this.player.sayHello.userID:"+sayHello.userID);
}
}
cc.log(Global.gint);
cc.log("helloWorld:"+helloWorld);
var hw=new helloWorld();
cc.log("hw:"+hw);
cc.log("text:"+hw.text);
},
// called every frame, uncomment this function to activate update callback
update: function (dt) {
cc.log("update..");
},
});
SayHello.js
Cocos Creator脚本开发事例的更多相关文章
- Cocos Creator 脚本模板
1.由于新建Cocos Creator脚本带有很多注释,并且有时候需要增加定制的默认注释,所以需要修改脚本生成模板. 2.在CocosCreator\resources\static\template ...
- Cocos Creator 游戏开发
Cocos Creator 游戏开发 https://www.cocos.com/products#CocosCreator 一体化编辑器: 包含了一体化.可扩展的编辑器,简化了资源管理.游戏调试和预 ...
- <8>Cocos Creator组件开发cc.Component
1.组件简介 组件是Cocos Creator的主要构成,渲染(场景显示内容).逻辑.用户输入反馈.计时器等等几个方面都是由组件完成的.根据Cocos Creator的总体架构,组件和节点配合完成游戏 ...
- <5>Cocos Creator 脚本简介
1.创建脚本 在资源管理器窗口中点击鼠标右键,显示菜单中点击新建,选择新建的脚本类型,这里举例就选择菜单中的JavaScript,或者如下图点击创建按钮也可. 新建后就会在资源管理器中出现一个NewS ...
- cocos creator 入门理解点
简单解释, [来源:官方文档] Cocos是触控科技推出的游戏开发一站式解决方案,包含了从新建立项.游戏制作.到打包上线的全套流程.开发者可以通过cocos快速生成代码.编辑资源和动画,最终输出适合于 ...
- Cocos Creator学习目录
目录 安装和启动 文件结构 编辑器基础 基本概念 (场景树 节点 坐标 组件 ) Cocos Creator 脚本简介 Cocos Creator调试 节点 cc.Node 组件开发cc.Compon ...
- <7>Cocos Creator 节点 cc.Node
1.简介 节点(cc.Node)是渲染的必要组成部分.所有需要在游戏场景中显示的内容都必须是节点或者依附于节点之上.节点负责控制显示内容的位置.大小.旋转.缩放.颜色等信息. 2.节点属性 1: na ...
- Cocos Creator中按钮组件数组的使用
Cocos Creator游戏开发中经常使用到按钮,特别是大量按钮的情况,此时使用数组来管理这些按钮就显得更具通用性.我大致走了一下官方的示例,好像没有发现有这个小内容(或者有,但我却是没有找到),于 ...
- Cocos Creator—如何给资源打MD5版本号
Cocos Creator 是Cocos最新一代的游戏开发者工具,基于 Cocos2d-x,组件化,脚本化,数据驱动,跨平台发布.Cocos Creator的开发思路已经逐步跟Unity 3D靠拢,写 ...
随机推荐
- Codeforces 1144G Two Merged Sequences dp
Two Merged Sequences 感觉是个垃圾题啊, 为什么过的人这么少.. dp[ i ][ 0 ]表示处理完前 i 个, 第 i 个是递增序列序列里的元素,递减序列的最大值. dp[ i ...
- Python 高级面向对象
一.字段 1.字段包括:普通字段和静态字段,他们在定义和使用中有所区别,而最本质的区别是内存中保存的位置不同. a.普通字段属于对象(实例变量) b.静态字段属于类(类变量) 二.属性 对于属性,有以 ...
- HTML元素粘滞融合效果
.target { filter: url("#goo"); } .ball { width: 150px; height: 150px; border-radius: 50%; ...
- HDU2449 Gauss Elimination 高斯消元 高精度 (C++ AC代码)
原文链接https://www.cnblogs.com/zhouzhendong/p/HDU2449.html 题目传送门 - HDU2449 题意 高精度高斯消元. 输入 $n$ 个 $n$ 元方程 ...
- Codechef STMINCUT S-T Mincut (CodeChef May Challenge 2018) kruskal
原文链接http://www.cnblogs.com/zhouzhendong/p/9010945.html 题目传送门 - Codechef STMINCUT 题意 在一个有边权的无向图中,我们定义 ...
- --mysql 导出数据时, 数字类型的列如果位数过长,变为科学计数法问题
--mysql 导出数据时, 数字类型的列如果位数过长,变为科学计数法问题在字段前加上\t即可select concat('\t',a.IDCARD_NO) from xxx a
- 20172328《程序设计与数据结构》实验三 敏捷开发与XP实践报告
20172328<程序设计与数据结构>实验三 敏捷开发与XP实践报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 李馨雨 学号:20172328 实验教师:王志强 ...
- 004.Ansible Ad-Hoc命令集
一 Ad-Hoc使用场景 Ad-Hoc更倾向于解决简单.临时性任务. 1.1 Ad-Hoc基础命令 基本语法: 1 ansible <host-pattern> [options] < ...
- html5手势操作与多指操作封装与Canvas图片裁切实战
当前情况,移动端的开发占比越来越高,单指的拖拽触碰等操作是常规需要.特殊的多指操作与手势操作还需另做处理,而且还涉及到兼容性问题. // 屏幕上存在两根或两根以上的手指 时触发 仅IOS存在手势事件, ...
- linux 学习笔记 cpio命令
1 文件或目录打包 打包有如下多种情况 A>包含子目录打包 find /usr/lib -print /cpio -o >/uo/temp1.cpio 将/usr/lib目录下的文件与子目 ...