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 837F Prefix Sums

    Prefix Sums 在 n >= 4时候直接暴力. n <= 4的时候二分加矩阵快速幂去check #include<bits/stdc++.h> #define LL l ...

  2. Count the string kmp

    问题描述众所周知,aekdycoin擅长字符串问题和数论问题.当给定一个字符串s时,我们可以写下该字符串的所有非空前缀.例如:S:“ABAB”前缀是:“A”.“AB”.“ABA”.“ABAB”对于每个 ...

  3. Spring日记_02之搭建一个新项目

    程序 表现层 业务层 持久层 从持久层开始写 总结如何搭建一个项目 1.新建一个Maven项目 2.可能新建之后会有错,右键Deployment Descriptor: note, 选择Generat ...

  4. httpd的rpm包及源码安装配置

    httpd的rpm包及源码安装配置 1.rpm包安装 系统环境: [root@zhaochj ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel ...

  5. web服务-1、http协议的三次握手四次挥手

    知识点:http协议:它是基于tcp协议的,浏览器访问服务器,服务器把资源回给浏览器,这个过程都是遵循http协议的,否则无法完成,http早些年是1.0版本,现在基本上都是1.1版本了,俩个版本的区 ...

  6. numpy 用于图像处理

    1. 转换为灰度图 灰度图的数据可以看成是二维数组,元素取值为0 ~ 255,其中,0为黑色,255为白色.从0到255逐渐由暗色变为亮色. 灰度图转换(ITU-R 601-2亮度变换): L = R ...

  7. js函数和变量的声明与执行顺序

    一.函数执行顺序 1.正常顺序 function f(){ alert(2); } f(); //alert 2 所有浏览器都能测试通过. 2.倒序调用 f(); //alert 2 function ...

  8. 无可奈何的开始了jquery的“奇淫技巧”

    转载请注明出处: https://home.cnblogs.com/u/zhiyong-ITNote/ 修改一个已有的项目,主要是前端方面,一般的项目后端都是处理好了的,不需要改也不能改,除非特殊需求 ...

  9. Jmeter压测过程报错the target server failed to respond

    失败事务报错信息如下, Socket closed Non HTTP response code: org.apache.http.NoHttpResponseException (the targe ...

  10. Android事件分发流程总结

    Action_Down 当按下一个控件,调用流程是Activity.dispatchTouchEvent -> ViewGroup.dispatchTouchEvent , 1.ViewGrou ...