HelloWorld.js

  1. window.Global = {
  2. gint: 168,
  3. };
  4. cc.Class({
  5. extends: cc.Component,
  6.  
  7. properties: {
  8. label: {
  9. default: null,
  10. type: cc.Label
  11. },
  12. // defaults, set visually when attaching this script to the Canvas
  13. text: 'Hello, World!'
  14. },
  15.  
  16. // use this for initialization
  17. onLoad: function () {
  18. this.label.string = this.text;
  19.  
  20. },
  21.  
  22. // called every frame
  23. update: function (dt) {
  24.  
  25. },
  26. });

HelloWorld.js

SayHello.js

  1. var helloWorld = require("HelloWorld");
  2. cc.Class({
  3. extends: cc.Component,
  4.  
  5. properties: {
  6. userID: {
  7. default: 20,
  8. displayName: "用户ID",
  9. tooltip: "用户的ID",
  10. },
  11. userName: "Foobar",
  12. pos: new cc.Vec2(10, 20),
  13. color: new cc.Color(255, 255, 255, 128),
  14. any: [], // 不定义具体类型的数组
  15. bools: [cc.Boolean],
  16. strings: [cc.String],
  17. floats: [cc.Float],
  18. ints: [cc.Integer],
  19. values: [cc.Vec2],
  20. nodes: [cc.Node],
  21. frames: [cc.SpriteFrame],
  22. score: {
  23. default: 0,
  24. displayName: "Score (player)",
  25. tooltip: "The score of player",
  26. },
  27. width: {
  28. get: function () {
  29. return this._width;
  30. },
  31. set: function (value) {
  32. this._width = value;
  33. }
  34. },
  35. player: {
  36. default: null,
  37. type: cc.Node
  38. }
  39. },
  40.  
  41. // use this for initialization
  42. onLoad: function () {
  43. var Shape = cc.Class({
  44. properties: {x:1},
  45. ctor: function () {
  46. cc.log("Shape"); // 实例化时,父构造函数会自动调用,
  47. },
  48. print: function (str) { cc.log("print:" + str+" x:"+this.node.x); },
  49. start: function () {
  50. var node = this.node;
  51. node.x = 100;
  52. }
  53. });
  54. var shape = new Shape();
  55. //shape.print("hello");
  56. //shape.start();
  57. var node = this.node;
  58. cc.log(node);
  59. cc.log(node.name);
  60. cc.log(node.color);
  61.  
  62. var sprite = this.getComponent("cc.Sprite");
  63. if(sprite!=null){
  64. cc.log("sprite.type:"+sprite.type);
  65. }
  66.  
  67. var label = this.getComponent("cc.Label");
  68. if(label!=null){
  69. cc.log("label:"+label.fontSize);
  70. }
  71. cc.log("this.userID:"+this.userID);
  72. if(this.player){
  73. var sprite2 = this.player.getComponent("cc.Sprite");
  74. cc.log("sprite2:"+sprite2);
  75. if(sprite2!=null){
  76. cc.log("this.player.sprite.type:"+sprite2.type);
  77. }
  78. var sayHello = this.player.getComponent("SayHello");
  79. cc.log("sayHello:"+sayHello);
  80. if(sayHello!=null){
  81. cc.log("this.player.sayHello.userID:"+sayHello.userID);
  82. }
  83. }
  84. cc.log(Global.gint);
  85. cc.log("helloWorld:"+helloWorld);
  86. var hw=new helloWorld();
  87. cc.log("hw:"+hw);
  88. cc.log("text:"+hw.text);
  89.  
  90. },
  91. // called every frame, uncomment this function to activate update callback
  92. update: function (dt) {
  93. cc.log("update..");
  94. },
  95. });

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. c_数据结构_顺序表

    #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define LIST_INIT_SIZE 100 // 线性表存储空间的初始分配量 #define ...

  2. Python_shelve模块

    shelve:对象持久化的保存的模块,将对象保存到文件里  (默认的数据存储文件为二进制),可持久化任何pickle可支持的Python数据格式 shelve 中唯一的方法: shelve.open( ...

  3. Codeforces 348D Turtles LGV

    Turtles 利用LGV转换成求行列式值. #include<bits/stdc++.h> #define LL long long #define fi first #define s ...

  4. git之一: git基础

    参考: SourceTree使用 git教程 廖学风git  文档1 文档2 1. git 概念介绍 工作区: 就是你在电脑里能看到的目录,比如我的learngit文件夹就是一个工作区,工作区下面有. ...

  5. Vue2.0学习——axios用法详解

    功能特性 在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 http请求 支持 Promise API 拦截请求和响应 转换请求和响应数据 自动转换 JSON 数据 客 ...

  6. BZOJ3560 DZY Loves Math V 数论 快速幂

    原文链接http://www.cnblogs.com/zhouzhendong/p/8111725.html UPD(2018-03-26):蒟蒻回来重新学数论了.更新了题解和代码.之前的怼到后面去了 ...

  7. BZOJ1856 [Scoi2010]字符串 数论

    原文链接http://www.cnblogs.com/zhouzhendong/p/8084577.html 题目传送门 - BZOJ1856 题意概括 找出由n个1,m个0组成的字符串,且任意前几个 ...

  8. Vijos1983 NOIP2015Day2T3 运输计划 transport LCA

    题目链接Vijos 题目链接UOJ 该博客在博客园的链接 转载一个大佬的题解: 点击这里->大佬题解 下面谈谈我的感悟: 当然写代码也是写的很艰辛: 我力劝C++的同胞们,这题卡常数,Dfs党会 ...

  9. Java中String直接赋字符串和new String的区别(面试常考)

    摘取自:https://www.cnblogs.com/guozhenqiang/p/5633269.html 解析Java中的String对象的数据类型 1. String是一个对象.  因为对象的 ...

  10. day16 函数的用法:内置函数,匿名函数

    思维导图需要补全 : 一共有68个内置函数: #内置:python自带 # def func(): # a = 1 # b = 2 # print(locals()) # print(globals( ...