1. Create a layervarGamelayer =cc. Layer.extend ({_time:NULL, _ship:NULL, _backsky:NULL, //constructor Functionctorfunction(){ This. _super (); This. Init (); }, //Note that you should have a comma //initialization functionInit:function () { return true; }, //member functionsScorecounter:function () { if( This. _state = =state_playing) { This. _time++; This. _levelmanager.loadlevelresource ( This. _time); } }, //with ParametersCollide:function(A, b) {varAx = a.x, ay = a.y, bx = b.x, by =b.y; if(Math.Abs (AX-BX) > Max_containt_width | | Math.Abs (ay-by) >max_containt_height)return false; varArect =a.colliderect (ax, ay); varBrect =B.colliderect (bx, by); returnCc.rectintersectsrect (Arect, brect); } //The last one can not need a comma});//If there is a need to switch scenes to the next interface, you can create this method,//You can enter this way after you get the scene.//Cc.director.runScene (New cc). Transitionfade (1.2, scene));Gamelayer.scene =function () { varScene =Newcc. Scene (); varLayer =NewGamelayer (); Scene.addchild (layer,1); returnscene;};//When you click Start a new game, the main game interface is loaded, which may require more resources to load//so it uses the Preload method, which is also the member function, which responds when the button is clicked.Onnewgame:function(psender) {//Load ResourcesCc. Loaderscene.preload (G_maingame,function() {cc.audioEngine.stopMusic (); Cc.audioEngine.stopAllEffects (); varScene =Newcc. Scene (); Scene.addchild (NewGamelayer ()); Scene.addchild (NewGamecontrolmenu ()); Cc.director.runScene (NewCc. Transitionfade (1.2, Scene)); }, This);},//load the plist filecc.spriteFrameCache.addSpriteFrames (res.texturetransparentpack_plist);//get the screen width highWinsize =cc.director.getWinSize ();//Create sprites, way onevarSP =Newcc. Sprite (res.loading_png); Sp.anchorx= 0; Sp.anchory= 0; Sp.scale=MW. scale; This. AddChild (SP, 0, 1);//This is the equivalent of self in Lua .//Create wizard mode twovarLogo =Newcc. Sprite (res.logo_png); Logo.attr ({anchorx:0, Anchory:0, x:0, Y:MW. Logoy, SCALE:MW. scale}); This. AddChild (Logo, 10, 1);//Create buttonvarNewgamenormal =NewAcl Sprite (res.menu_png, cc.rect (0, 0, Singalwidth, Singalheight));varnewgameselected =NewAcl Sprite (res.menu_png, cc.rect (0, Singalheight, Singalwidth, Singalheight));varnewgamedisabled =NewAcl Sprite (res.menu_png, cc.rect (0, Singalheight * 2, Singalwidth, Singalheight));varNewgame =NewAcl Menuitemsprite (Newgamenormal, newgameselected, newgamedisabled,function () { //The response function of the button}.bind ( This)); Newgame.scale= MW. scale;//Setting Propertiesvarmenu =Newcc. Menu (Newgame, gamesettings, about); Menu.alignitemsverticallywithpadding (15); This. AddChild (menu, 1, 2);//Frame events, This. Schedule ( This. Update, 0.1); Update:function () { if( This. _ship.y > 750) { This. _ship.x = Math.random () *Winsize.width; This. _ship.y = 10; This. _ship.runaction (Cc.moveby (parseint (5 * math.random (), 10), CC.P (Math.random ()* Winsize.width, This. _SHIP.Y + 750) )); } },//Action This. _ship =NewCc. Sprite ("#ship03. png"); This. _ship.runaction (Cc.moveby (2, CC.P (Math.random () * Winsize.width, This. _ship.y + winsize.height + 100)));//JS Arrayhttp//www.w3school.com.cn/jsref/jsref_obj_array.asp//JS Boolean Objecthttp//www.w3school.com.cn/jsref/jsref_obj_boolean.asp//This pointer//the This pointer about JavaScript is similar to C++/java. Let's look at an example: (This example is very simple, I will not say more)functionPrint (text) {document.write ( This. Value + '-' + text+ ' <br> '); //here is the object that calls the print function} varA = {Value:10, print:print};varb = {Value:20, print:print}; Print (' Hello ');//This = global, Output "Undefined-hello"A.print (' A ');//This = A, Output "10-a"B.print (' B ');//This = B, Output "20-b"a[' Print '] (' a ');//This = A, Output "10-a"
Http://www.php100.com/html/webkaifa/javascript/2012/0228/9927.html
http://www.ibm.com/developerworks/cn/web/1304_zengyz_jsoo/
JS Note--1