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. Codeforces 989D A Shade of Moonlight

    A Shade of Moonlight 列列式子发现, 对于同一个云来说只有反向的云才能和它相交, 然后我们发现这个东西有单调性,然后二分就好啦. #include<bits/stdc++.h ...

  2. Fstring

    题目描述 一个只包含A,B,C三种字符的字符串,如果其中有连续的3个由A,B,C各一个组成,则称为Fstring. 例如:BAACAACCBAAA就是,而AABBCCAABB则不是. 你的任务就是计算 ...

  3. /bin/sh ./xxxxx.sh出现:“Syntax error: “(” unexpected”

    Ubuntu/Debian为了加快开机速度,用dash代替了bash. dpkg-reconfigure dash 选择 No,取消dash即可,要重新开启dpkg-reconfigure dash选 ...

  4. JavaSE| 流程控制

    程序流程控制 流程控制语句结构: .顺序结构 语句的关系是从上到下依次执行的顺序关系,中间没有任何判断和跳转: 它是最基本的结构,Java程序总体来说都是从main()依次执行 .分支结构: 根据条件 ...

  5. 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。

    该题还是考杨辉三角计算,只不过最后每一行都放入List集合中,然后返回,直接看代码: public static List<List<Integer>> generate(in ...

  6. 组合数的简单求法(dfs)

    组合数的具体应用可以参考这个例子:https://www.cnblogs.com/FengZeng666/p/10496223.html 下面这段代码可以作为求组合数的固定套路或者公式: #inclu ...

  7. 爬虫2 urllib用法

    from urllib import request,parse # 1. 解析数据 # 解析一条 # response = request.urlopen(url='http://httpbin.o ...

  8. Python之IO编程——文件读写、StringIO/BytesIO、操作文件和目录、序列化

    IO编程 IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口.从 ...

  9. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  10. P1168 中位数

    P1168 中位数树状数组+二分答案.树状数组就是起一个高效查询比二分出来的数小的有几个. #include<iostream> #include<cstdio> #inclu ...