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靠拢,写 ...
随机推荐
- c_数据结构_顺序表
#define OK 1 #define ERROR 0 #define OVERFLOW -2 #define LIST_INIT_SIZE 100 // 线性表存储空间的初始分配量 #define ...
- Python_shelve模块
shelve:对象持久化的保存的模块,将对象保存到文件里 (默认的数据存储文件为二进制),可持久化任何pickle可支持的Python数据格式 shelve 中唯一的方法: shelve.open( ...
- Codeforces 348D Turtles LGV
Turtles 利用LGV转换成求行列式值. #include<bits/stdc++.h> #define LL long long #define fi first #define s ...
- git之一: git基础
参考: SourceTree使用 git教程 廖学风git 文档1 文档2 1. git 概念介绍 工作区: 就是你在电脑里能看到的目录,比如我的learngit文件夹就是一个工作区,工作区下面有. ...
- Vue2.0学习——axios用法详解
功能特性 在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 http请求 支持 Promise API 拦截请求和响应 转换请求和响应数据 自动转换 JSON 数据 客 ...
- BZOJ3560 DZY Loves Math V 数论 快速幂
原文链接http://www.cnblogs.com/zhouzhendong/p/8111725.html UPD(2018-03-26):蒟蒻回来重新学数论了.更新了题解和代码.之前的怼到后面去了 ...
- BZOJ1856 [Scoi2010]字符串 数论
原文链接http://www.cnblogs.com/zhouzhendong/p/8084577.html 题目传送门 - BZOJ1856 题意概括 找出由n个1,m个0组成的字符串,且任意前几个 ...
- Vijos1983 NOIP2015Day2T3 运输计划 transport LCA
题目链接Vijos 题目链接UOJ 该博客在博客园的链接 转载一个大佬的题解: 点击这里->大佬题解 下面谈谈我的感悟: 当然写代码也是写的很艰辛: 我力劝C++的同胞们,这题卡常数,Dfs党会 ...
- Java中String直接赋字符串和new String的区别(面试常考)
摘取自:https://www.cnblogs.com/guozhenqiang/p/5633269.html 解析Java中的String对象的数据类型 1. String是一个对象. 因为对象的 ...
- day16 函数的用法:内置函数,匿名函数
思维导图需要补全 : 一共有68个内置函数: #内置:python自带 # def func(): # a = 1 # b = 2 # print(locals()) # print(globals( ...