// // http://www.cocos2d-iphone.org // // Javascript + chipmunk tests // require("js/helper.js"); director = cc.Director.getInstance(); winSize = director.getWinSize(); centerPos = cc.p( winSize.width/2, winSize.height/2 ); var scenes = [] var currentScene = 0; var withTransition = false; var nextScene = function () { currentScene = currentScene + 1; if( currentScene >= scenes.length ) currentScene = 0; withTransition = true; loadScene(currentScene); }; var previousScene = function () { currentScene = currentScene -1; if( currentScene < 0 ) currentScene = scenes.length -1; withTransition = true; loadScene(currentScene); }; var restartScene = function () { loadScene( currentScene ); }; var loadScene = function (sceneIdx) { winSize = director.getWinSize(); centerPos = cc.p( winSize.width/2, winSize.height/2 ); var scene = new cc.Scene(); scene.init(); var layer = new scenes[ sceneIdx ](); scene.addChild( layer ); // scene.walkSceneGraph(0); var transitions = [ cc.TransitionSplitCols, cc.TransitionSplitRows, cc.TransitionSlideInL, cc.TransitionSlideInR, cc.TransitionSlideInT, cc.TransitionSlideInB, cc.TransitionFade, cc.TransitionCrossFade, cc.TransitionFlipX, cc.TransitionFlipY, cc.TransitionProgressRadialCCW, cc.TransitionProgressRadialCW, cc.TransitionProgressVertical, cc.TransitionProgressHorizontal, cc.TransitionShrinkGrow, ]; var idx = Math.floor( Math.random() * transitions.length ); var transition = transitions[ idx ]; if( withTransition == true ) director.replaceScene( transition.create( 0.9, scene ) ); else director.replaceScene( scene ); withTransition = false; // __jsc__.garbageCollect(); } //------------------------------------------------------------------ // // BaseLayer // //------------------------------------------------------------------ var BaseLayer = function() { // // VERY IMPORTANT // // Only subclasses of a native classes MUST call __associateObjectWithNative // Failure to do so, it will crash. // var parent = goog.base(this); __associateObjWithNative( this, parent ); this.init( cc.c4b(0,0,0,255), cc.c4b(0,128,255,255)); this.title = "No title"; this.subtitle = "No Subtitle"; this.isMainTitle = false; } goog.inherits(BaseLayer, cc.LayerGradient ); // // Instance 'base' methods // XXX: Should be defined after "goog.inherits" // BaseLayer.prototype.onEnter = function() { var fontSize = 36; var tl = this.title.length; fontSize = (winSize.width / tl) * 1.60; if( fontSize/winSize.width > 0.09 ) { fontSize = winSize.width * 0.09; } this.label = cc.LabelTTF.create(this.title, "Gill Sans", fontSize); this.addChild(this.label, 100); var isMain = this.isMainTitle; if( isMain == true ) this.label.setPosition( centerPos ); else this.label.setPosition( cc.p(winSize.width / 2, winSize.height*11/12) ); var subStr = this.subtitle; if (subStr != "") { tl = this.subtitle.length; var subfontSize = (winSize.width / tl) * 1.3; if( subfontSize > fontSize *0.6 ) { subfontSize = fontSize *0.6; } this.sublabel = cc.LabelTTF.create(subStr, "Thonburi", subfontSize); this.addChild(this.sublabel, 90); if( isMain ) this.sublabel.setPosition( cc.p(winSize.width / 2, winSize.height*3/8 )); else this.sublabel.setPosition( cc.p(winSize.width / 2, winSize.height*5/6 )); } else this.sublabel = null; // Menu var item1 = cc.MenuItemImage.create("b1.png", "b2.png", this, this.backCallback); var item2 = cc.MenuItemImage.create("r1.png", "r2.png", this, this.restartCallback); var item3 = cc.MenuItemImage.create("f1.png", "f2.png", this, this.nextCallback); var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } ); item4.setFontSize( 22 ); [item1, item2, item3 ].forEach( function(item) { item.normalImage().setOpacity(45); item.selectedImage().setOpacity(45); } ); var menu = cc.Menu.create( item1, item2, item3, item4 ); menu.setPosition( cc.p(0,0) ); item1.setPosition( cc.p(winSize.width / 2 - 100, 30)); item2.setPosition( cc.p(winSize.width / 2, 30)); item3.setPosition( cc.p(winSize.width / 2 + 100, 30)); item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) ); this.addChild(menu, 80); } BaseLayer.prototype.createBulletList = function () { var str = ""; for(var i=0; i