1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function resourceCallBack(){
cc.game.onStart = function(){
cc.view.adjustViewPort(true);//是否自动添加viewport
if(thisismobile){
cc.view.setDesignResolutionSize(640, 1136, cc.ResolutionPolicy.EXACT_FIT);
}else{
cc.view.setDesignResolutionSize(640, 1136, cc.ResolutionPolicy.SHOW_ALL);
}
cc.view.enableAutoFullScreen(false);//是否自动全屏 最好放置于下行前
cc.view.resizeWithBrowserSize(false);//根据浏览器窗口改变
//load resources
MyLoaderScene.preload(g_resources, function () {
cc.director.runScene(new gameScene());
}, this);
};
cc.game.run("gameCanvas");
}
1
2
3
4
5
6
7
8
9
10
var _frames = [];
for(var i = 0; i < 5; i++){
var frame = new cc.SpriteFrame(this.texture,cc.rect(356 * i, 0, 356, 209));
_frames.push(frame);
}
var _Animation = new cc.Animation(_frames, 0.01);
_Animation.setRestoreOriginalFrame(true);
// var _Animate = cc.Animate.create(_Animation).repeatForever();
var _Animate = cc.Animate.create(_Animation);
this.runAction(_Animate);
1
2
layer 此类默认设置锚点无效
须加上 this.ignoreAnchorPointForPosition(flase);
1
2
3
4
5
6
7
8
9
10
11
// 在第二种情况下,alpha不生效
var shareLayer = cc.LayerColor.extend({
name : "shareLayer",
ctor : function(){
// 1.
this._super(cc.color(0, 0, 0, 125));

// 2.
// this.color = cc.color(0,0,0,125);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
这里要把swallowTouches设置为true,这样onTouchBegan返回true才能够吞噬触摸,不继续往优先级更低的层传递,从而实现遮挡层。所以 onTouchDispose处理方法不能在onTouchBegan  !!! 返回true之前!!!执行。
loadListener : function(){
var listener = cc.EventListener.create({
event : cc.EventListener.TOUCH_ONE_BY_ONE,
target : this,
swallowTouches : true,
onTouchBegan : this.onTouchBegan,
onTouchMoved : this.onTouchMoved,
onTouchEnded : this.onTouchEnded
});
cc.eventManager.addListener(listener, this);
},
onTouchBegan: function (touch, event) {
var self = this.target;
var locationInNode = self.convertToNodeSpace(touch.getLocation());
var size = self.getContentSize();
var rect = cc.rect(0, 0, size.width, size.height);
if (!cc.rectContainsPoint(rect, locationInNode)) {
return false;
}
return true;

},
onTouchMoved : function (touch, event) {
var self = this.target;
},
onTouchEnded : function (touch, event) {
var self = this.target;

// 触摸处理
self.onTouchDispose();
},
onTouchDispose : function(){
// TODO...
}
1
2
//layer 节点 徐设置这个为ture下方可用cc.fadeOut();
this.setCascadeOpacityEnabled(true);