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脚本开发事例的更多相关文章

  1. Cocos Creator 脚本模板

    1.由于新建Cocos Creator脚本带有很多注释,并且有时候需要增加定制的默认注释,所以需要修改脚本生成模板. 2.在CocosCreator\resources\static\template ...

  2. Cocos Creator 游戏开发

    Cocos Creator 游戏开发 https://www.cocos.com/products#CocosCreator 一体化编辑器: 包含了一体化.可扩展的编辑器,简化了资源管理.游戏调试和预 ...

  3. <8>Cocos Creator组件开发cc.Component

    1.组件简介 组件是Cocos Creator的主要构成,渲染(场景显示内容).逻辑.用户输入反馈.计时器等等几个方面都是由组件完成的.根据Cocos Creator的总体架构,组件和节点配合完成游戏 ...

  4. <5>Cocos Creator 脚本简介

    1.创建脚本 在资源管理器窗口中点击鼠标右键,显示菜单中点击新建,选择新建的脚本类型,这里举例就选择菜单中的JavaScript,或者如下图点击创建按钮也可. 新建后就会在资源管理器中出现一个NewS ...

  5. cocos creator 入门理解点

    简单解释, [来源:官方文档] Cocos是触控科技推出的游戏开发一站式解决方案,包含了从新建立项.游戏制作.到打包上线的全套流程.开发者可以通过cocos快速生成代码.编辑资源和动画,最终输出适合于 ...

  6. Cocos Creator学习目录

    目录 安装和启动 文件结构 编辑器基础 基本概念 (场景树 节点 坐标 组件 ) Cocos Creator 脚本简介 Cocos Creator调试 节点 cc.Node 组件开发cc.Compon ...

  7. <7>Cocos Creator 节点 cc.Node

    1.简介 节点(cc.Node)是渲染的必要组成部分.所有需要在游戏场景中显示的内容都必须是节点或者依附于节点之上.节点负责控制显示内容的位置.大小.旋转.缩放.颜色等信息. 2.节点属性 1: na ...

  8. Cocos Creator中按钮组件数组的使用

    Cocos Creator游戏开发中经常使用到按钮,特别是大量按钮的情况,此时使用数组来管理这些按钮就显得更具通用性.我大致走了一下官方的示例,好像没有发现有这个小内容(或者有,但我却是没有找到),于 ...

  9. Cocos Creator—如何给资源打MD5版本号

    Cocos Creator 是Cocos最新一代的游戏开发者工具,基于 Cocos2d-x,组件化,脚本化,数据驱动,跨平台发布.Cocos Creator的开发思路已经逐步跟Unity 3D靠拢,写 ...

随机推荐

  1. Java基础总结02:环境变量的配置

    (一)Windows系统下配置环境变量 ※在"系统变量"中设置3项属性JAVA_HOME.PATH.CLASSPATH(JDK1.5之后此项属性不必再配),若已存在则点击" ...

  2. 如何在不使用try语句的情况下查看文件是否存在

    如果你要确定文件存在的话然后做些什么,那么使用try是最好不过的 如果您不打算立即打开文件,则可以使用os.path.isfile检查文件 如果path是现有常规文件,则返回true.对于相同的路径, ...

  3. LoadRunner录制协议的选择

    1.选择协议(提高测试结果的准确性) New Single Protocol Script:单协议脚本,选择一种主协议进行测试 New Multiple Protocol Script:多协议脚本,选 ...

  4. css 其他

    去掉border和padding占用设置元素额外的宽高,使浏览器显示的元素宽高+border+padding的总和与设置的一致,它在浏览器的总宽=40px-border-padding (默认时: 设 ...

  5. es6的模块化--AMD/CMD/commonJS/ES6

    , ); ); }) , )); }); , )); ; export { firstName, lastName, year }; // es6引用 import { firstName, last ...

  6. Python库: PrettyTable 模块

    一,PrettyTable简介 PrettyTable是python中的一个第三方库,可用来生成美观的ASCII格式的表格: 二,PrettyTable安装 使用PIP即可十分方便的安装PrettyT ...

  7. Django的请求生命周期

    Django的请求生命周期 请求生命周期 请求生命周期是指当用户在浏览器上输入url到用户看到网页的这个时间段内,Django后台所发生的事情. 1.客户端发送Http请求 2 .服务器接收,根据请求 ...

  8. 使用Nginx+uwsgi在亚马逊云服务器上部署python+django项目完整版(二)——部署配置及相关知识

    ---恢复内容开始--- 一.前提: 1.django项目文件已放置在云服务器上,配置好运行环境,可正常运行 2.云服务器可正常连接 二.相关知识 1.python manage.py runserv ...

  9. CLR Via 第一 章 知识点整理(1)

    写这个纯粹是自己的一点学习总结,其实就学习的笔记整理,相当于对自己的一点督促,如有看到不正确的欢迎指出 一般我们写代码都是使用的高级语言,但是在CLR中运行的代码并不是我们直接写的代码,而是通过我们选 ...

  10. mySql的UDF是什么

    CRUD:添删改查 UDF是mysql的一个拓展接口,UDF(Userdefined function)可翻译为用户自定义函数,这个是用来拓展Mysql的技术手段. 1 MySQL简介 MySQL是最 ...