main.js代码

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
36
37
cc.game.onStart = function(){
cc.view.adjustViewPort(true);
cc.view.setDesignResolutionSize(1334,750,1);
cc.view.resizeWithBrowserSize(true);
LoaderScene.preload(gameResources, function () {
var start = new Start();
cc.director.runScene(start);
}, this);
};
cc.game.run("gameCanvas");

window.addEventListener('resize',rotateHandler,false);
function rotateHandler(){
if(!cc || !cc.director || !cc.director.getRunningScene) return;
var currentScene = cc.director.getRunningScene();
var resize = currentScene._resize;
if(typeof resize === 'function'){
var rate = 1,deg = 0,
width = document.documentElement.clientWidth,
height = document.documentElement.clientHeight,
tempVal = 0;
if(width<height){
rate = width/height;
tempVal = width;
width = height;
height = tempVal;
deg = 90;
pageIsturned = true;
}else{
pageIsturned = false;
}
resize.call(currentScene,deg,rate,{
width:width,
height:height
});
}
}

start.js代码

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var Start = window.Start = cc.Scene.extend({
_screenLayer: null,
_startLayer:null,
_gameLayer:null,
_isInit: false,
ctor: function(){
this._super();
},
onEnter: function(){
this._isInit = true;

//------------------TODO------------------//

this._screenLayer = new cc.Layer();
this.addChild(this._screenLayer);

this._startLayer = new StartLayer();
this._screenLayer.addChild(this._startLayer);

//------------------TODO------------------//

if(typeof rotateHandler === 'function') {
rotateHandler();
}
this._super();
},
onExit: function(){
// cc.spriteFrameCache.removeSpriteFramesFromFile(res.catIndex);
},
_resize: function(deg,rate,size){
if(!this._isInit) return;
this._screenLayer.rotation = deg;
this._screenLayer.scale = rate;

this._startLayer._resize(size);
}
});

var StartLayer = cc.Layer.extend({
_bg:null,
_cat:null,
_frameCount:0,
_catIsMoving: false,
ctor: function(){
this._super();

this._bg = new cc.Sprite(res.mainBg);
this._bg.x = cc.winSize.width/2;
this._bg.y = cc.winSize.height/2;
this.addChild(this._bg);

this.round1 = new cc.Sprite(res.round1);
this.round1.x = cc.winSize.width/2;
this.round1.y = cc.winSize.height/2;
this.round1.scale = 0.3;
this.addChild(this.round1);

var r = new cc.rotateBy(0.6, 360).repeatForever();
this.round1.runAction(r);

this.round2 = new cc.Sprite(res.round2);
this.round2.x = cc.winSize.width/2 - 100;
this.round2.y = cc.winSize.width/2 - 100;
this.addChild(this.round2);
},
_resize : function(size){
var height = cc.winSize.height,
width = cc.winSize.width;
if(width/height>=size.width/size.height){
width = height*size.width/size.height;
}else{
height = width*size.height/size.width;
}

this.round2.x = (size.width + width) / 2 + 10;
this.round2.y = (size.height + height) / 2 + 10;
}
});