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靠拢,写 ...
随机推荐
- ArcGIS 10开发迁移策略(待续)
1.更改 ESRI.ArcGIS.ADF 程序集 ArcGIS 10 中, ADF 程序集中的功能被分散到不同的程序集中,如果将 ArcGIS 9.3 下 开发的自定义组件迁移到 ArcGIS 10 ...
- cactiEZ 配置
CactiEZ 中文版是简单有效的cacti中文解决方案,它基于centos6 整合了cacti的相关软件,重新编译的一个新的操作系统 它基于centos6,启动速度快,支持EXT4文件系统,全中文页 ...
- Codeforces 219E Parking Lot 线段树
Parking Lot 线段树区间合并一下, 求当前要占的位置, 不包括两端点的写起来方便一点. #include<bits/stdc++.h> #define LL long long ...
- axios中文文档
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. Features 从浏览器中创建 XMLHttpRequests 从 node.js 创建 http ...
- BZOJ1095 [ZJOI2007]Hide 捉迷藏 动态点分治 堆
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ1095.html 题目传送门 - BZOJ1095 题意 有 N 个点,每一个点是黑色或者白色,一开始所 ...
- BZOJ1823 [JSOI2010]满汉全席 2-sat
原文链接http://www.cnblogs.com/zhouzhendong/p/8125944.html 题目传送门 - BZOJ1823 题意概括 有n道菜,分别可以做成满式和汉式(每道菜只能做 ...
- LCA算法解析-Tarjan&倍增&RMQ
原文链接http://www.cnblogs.com/zhouzhendong/p/7256007.html UPD(2018-5-13) : 细节修改以及使用了Latex代码,公式更加美观.改的过程 ...
- LoadRunner脚本参数化之自动关联和手动关联
一.关联的意义 1.关联的含义 关联(correlation):在脚本回放过程中,客户端发出请求,通过关联函数所定义的左右边界值(也就是关联规则),在服务器所响应的内容中查找,得到相应的值,以变量的 ...
- 无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换
无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换 前言: Maya 集成了 PySide,同时集成了qt designer,在 Maya 的安装目录下的 bin ...
- TF:利用TF的train.Saver将训练好的variables(W、b)保存到指定的index、meda文件—Jason niu
import tensorflow as tf import numpy as np W = tf.Variable([[2,1,8],[1,2,5]], dtype=tf.float32, name ...