- layout 父节点透明子节点不透明 creator 2.0 已经移除了 cascadeOpacity 的相关方法
解决办法--> 给layout中的sprite设置一张透明的图片。 完美解决
- creator 代码中的require的文件不能加 .js
require("gameData.js") 要改为 require("gameData"), 否则微信小程序里会报错,can not find module gameData
- cc.Label组件设置string没有及时更改
this.btn_pause.node.getChildByName("lb_text").string = this.status ? "继续" : "暂停";
这样写的结果导致按钮上的文字并没有及时更改,正确的方式是
var lb_text = this.btn_pause.node.getChildByName("lb_text");
lb_text.getComponent(cc.Label).string = this.status ? "继续" : "暂停";
- sprite 赋值 resources 目录下的方法 :两种
// 通过cc.rul.row var cocos = this.node.getChildByName("cocos"); cocos.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(cc.url.raw("resources/helloworld/snow.png")); // 通过cc.loader.loadRes var myImage = cc.find("Canvas/myImage").getComponent(cc.Sprite); cc.loader.loadRes("helloworld/table.png", cc.SpriteFrame, function(err, spFrame) { myImage.spriteFrame = spFrame; }) var myImage2 = cc.find("Canvas/myImage2").getComponent(cc.Sprite); cc.loader.loadRes("plists/cards.plist", cc.SpriteAtlas, function(err, atlas) { // 方法一 通过数组加载 // myImage2.spriteFrame = atlas.getSpriteFrames()[0]; // 方法二 通过名字加载 myImage2.spriteFrame = atlas.getSpriteFrame("bug_orange_1"); });
//声音加载
cc.audioEngine.playMusic(this.bg_muisc, true); // 动态加载 cc.loader.loadRes("voices/audio/niu.mp3", cc.AudioClip, function(err, voice) { cc.audioEngine.playMusic(voice, true); });
- 动态资源加载 放到 assets/resources 目录下
- cc 的理解。 cc 是全局对象, 在游戏登陆的时候初始化全局变量可以赋值给cc.game cc.user 这样就可以全局使用了。
即使切换场景了,cc.x 复制的东西还是存在的
- 反转node 水平反转,设置scaleX = -1, 垂直反转 scaleY = -1;
- 设置按钮的隐藏,只能用 self.btn_fight.node.active = true;
不能用self.btn_fight.getComponent(cc.Node).active = true;
- 全局 消息监听和发送, cc.director.on() , cc.director.off(), cc.director.emit();
-
console.log("-----------changeCock-cock/animations/ji" + info.id + "/ji" + info.id + ".atlas");
通过 cc.loader.loadRes , 第一个param 不应该加 后缀, 否则会显示不成功
cc.loader.loadRes("cock/animations/ji" + info.id + "/ji" + info.id, sp.SkeletonData, function(err, spine) {
- cc.director 可以执行 once 注册事件,回调会在第一时间被触发后删除自身。
也可以通过cc.director dispatchEvent 通过对象派发事件。
- 设置背景随文字长度变化,: 9宫格。Node. 添加cc.Spirte 设置背景图片,sprite types设置成Sliced. 再添加一个Layout
-
let widget = bg.addComponent(cc.Widget); widget.alignMode = 1; widget.isAlignBottom = true; widget.isAlignLeft = true; widget.isAlignRight = true; widget.isAlignTop = true; widget.target = this.node;
- cc.BlockInputEvents 添加可以使 node 吞噬触摸
// node.addComponent(cc.BlockInputEvents);
- cc.EventTarget
// 使用这个可以在多个没有依赖关系的,A,B,C,D上添加同一个监听事件fire,在消息分发emit(EventA)后,ABCD四处地方都可以响应这个事件```js
eventTarget.on('fire', function () {
cc.log("fire in the hole");
}, A(|| B || C || D));
``` - node on 监听,
nodeA->B->C
在ABC 同时监听fire事件,在C消息分发emit("fire")后,会依次上传B,然后到A,在BC监听消息回调不会触发。
如果想让事件阻止向上传递,event.stopPropagation()
- 设置是否在左下角显示 FPS
cc.debug.setDisplayStats(CC_DEBUG);
-
Animation 提供了一系列可注册的事件:
- play : 开始播放时
- stop : 停止播放时
- pause : 暂停播放时
- resume : 恢复播放时
- lastframe : 假如动画循环次数大于 1,当动画播放到最后一帧时
- finished : 动画播放完成时 */ -
ts 共用单例类
export class SingleBase extends cc.EventTarget { public static getInstance<T>(this: new () => T): T { if (!(<any>this).instance) { (<any>this).instance = new this(); (<any>this).instance.init(); } return (<any>this).instance; } public static deleteInstance() { if ((<any>this).instance) { (<any>this).instance.clear(); delete (<any>this).instance; } } public init(name: any, ...args) { return this; } public clear(): void { } }
-
4
-
5
-
6
-
7
-
8
-
9
-
0
-
-