diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..081a441553 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "echoCommand": true, + "tasks": [ + { + "label": "Build", + "type": "shell", + "command": "ant", + "group": { + "kind": "build", + "isDefault": true + }, + "args": [ + "-f", + "tools/build.xml" + ], + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "dedicated" + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/CCBoot.js b/CCBoot.js index ebe862bedb..b5a14a1649 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2096,6 +2096,9 @@ var _initSys = function () { * @return {Number} */ sys.now = function () { + if (window.performance.now) { + return window.performance.now() + window.performance.timing.navigationStart; + } if (Date.now) { return Date.now(); } diff --git a/README.mdown b/README.mdown index 57823c8723..5cdd83f1c4 100644 --- a/README.mdown +++ b/README.mdown @@ -1,52 +1,13 @@ -Cocos2d-html5 +Cocos2d-html5 (BlueCanoe Fork) ================== -[Cocos2d-html5][1] is a cross-platform 2D game engine written in JavaScript, based on [Cocos2d-X][2] and licensed under MIT. -It incorporates the same high level api as “Cocos2d JS-binding engine” and compatible with Cocos2d-X. -It currently supports canvas and WebGL renderer. +Fork of [Cocos2d-html5](https://github.com/cocos2d/cocos2d-html5). +Making a few changes and cherry picking pull requests to suit our games. -Cross Platform +Build ------------- - * Popular browsers: Chrome 14+, Safari 5.0+, IE9+, Firefox 3.5+. - * Mobile platforms: coming soon. - * Native App: Same piece of code can run on "Cocos2d JS-Binding Engine" without or with little modification. -Documentation ------------------- - * Website: [www.cocos2d-x.org][3] - * API References: [http://www.cocos2d-x.org/wiki/Reference] [4] - - -Installing from [bower][8] (version >=3.4) ------------------- - -```shell -$ bower install cocos2d-html5 -``` - -Running the tests (version <3) ------------------- - -```shell -$ git clone git://github.com/cocos2d/cocos2d-html5.git -$ cd cocos2d-html5 -$ git submodule update --init -$ python -m SimpleHTTPServer -``` -... and then open a browser and go to `http://localhost:8000/tests` - - -Contact us ------------------- - * Forum: [http://forum.cocos2d-x.org][5] - * Twitter: [http://www.twitter.com/cocos2dhtml5][6] - * Sina Microblog: [http://t.sina.com.cn/cocos2dhtml5][7] - -[1]: http://www.cocos2d-x.org "Cocos2d-html5" -[2]: http://www.cocos2d-x.org "Cocos2d-X" -[3]: http://www.cocos2d-x.org "www.cocos2d-x.org" -[4]: http://www.cocos2d-x.org/wiki/Reference "API References" -[5]: http://forum.cocos2d-x.org "http://forum.cocos2d-x.org" -[6]: http://www.twitter.com/cocos2dhtml5 "http://www.twitter.com/cocos2dhtml5" -[7]: http://t.sina.com.cn/cocos2dhtml5 "http://t.sina.com.cn/cocos2dhtml5" -[8]: http://bower.io "http://bower.io" +Much easier to build than the original repo. +* Install [apache ant](http://ant.apache.org/) +* Run `ant -f tools/build.xml` +* Alternatively, open in VSCode and run the build task (Cmd+B by default) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index b8a021f43c..a0dfd26072 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -101,9 +101,9 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ ctor: function () { var self = this; - self._lastUpdate = Date.now(); + self._lastUpdate = window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () { - self._lastUpdate = Date.now(); + self._lastUpdate = window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); }); }, @@ -118,7 +118,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ // FPS this._totalFrames = 0; - this._lastUpdate = Date.now(); + this._lastUpdate = window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); //Paused? this._paused = false; @@ -157,7 +157,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ * calculates delta time since last time it was called */ calculateDeltaTime: function () { - var now = Date.now(); + var now = window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); // new delta time. if (this._nextDeltaTimeZero) { @@ -167,9 +167,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ this._deltaTime = (now - this._lastUpdate) / 1000; } - if ((cc.game.config[cc.game.CONFIG_KEY.debugMode] > 0) && (this._deltaTime > 0.2)) - this._deltaTime = 1 / 60.0; - this._lastUpdate = now; }, @@ -473,7 +470,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ } this.setAnimationInterval(this._oldAnimationInterval); - this._lastUpdate = Date.now(); + this._lastUpdate = window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); if (!this._lastUpdate) { cc.log(cc._LogInfos.Director_resume); } @@ -802,7 +799,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ }, _calculateMPF: function () { - var now = Date.now(); + var now = window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); this._secondsPerFrame = (now - this._lastUpdate) / 1000; } }); diff --git a/cocos2d/core/platform/CCInputExtension.js b/cocos2d/core/platform/CCInputExtension.js index e61f58459a..d02558c389 100644 --- a/cocos2d/core/platform/CCInputExtension.js +++ b/cocos2d/core/platform/CCInputExtension.js @@ -121,7 +121,7 @@ _p.didAccelerate = function (eventData) { mAcceleration.y = y; mAcceleration.z = z; - mAcceleration.timestamp = eventData.timeStamp || Date.now(); + mAcceleration.timestamp = eventData.timeStamp || (window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : Date.now()); var tmpX = mAcceleration.x; if(w.orientation === cc.UIInterfaceOrientationLandscapeRight){ diff --git a/cocos2d/core/platform/CCInputManager.js b/cocos2d/core/platform/CCInputManager.js index 270c535c7d..fc3b2fe83b 100644 --- a/cocos2d/core/platform/CCInputManager.js +++ b/cocos2d/core/platform/CCInputManager.js @@ -408,6 +408,17 @@ cc.inputManager = /** @lends cc.inputManager# */{ var selfPointer = this; var supportMouse = ('mouse' in cc.sys.capabilities), supportTouches = ('touches' in cc.sys.capabilities); + var supportsPassive = false; + try { + var opts = Object.defineProperty({}, 'passive', { + get: function () { + supportsPassive = true; + } + }); + window.addEventListener("testPassive", null, opts); + window.removeEventListener("testPassive", null, opts); + } catch (e) { } + //HACK // - At the same time to trigger the ontouch event and onmouse event // - The function will execute 2 times @@ -442,7 +453,7 @@ cc.inputManager = /** @lends cc.inputManager# */{ mouseEvent.setButton(event.button); cc.eventManager.dispatchEvent(mouseEvent); } - }, false); + }, supportsPassive ? { passive: true } : false); //register canvas mouse event element.addEventListener("mousedown", function (event) { @@ -459,9 +470,9 @@ cc.inputManager = /** @lends cc.inputManager# */{ cc.eventManager.dispatchEvent(mouseEvent); event.stopPropagation(); - event.preventDefault(); + !supportsPassive && event.preventDefault(); element.focus(); - }, false); + }, supportsPassive ? { passive: true } : false); element.addEventListener("mouseup", function (event) { if (prohibition) return; @@ -477,8 +488,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ cc.eventManager.dispatchEvent(mouseEvent); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); element.addEventListener("mousemove", function (event) { if (prohibition) return; @@ -496,8 +507,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ cc.eventManager.dispatchEvent(mouseEvent); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); element.addEventListener("mousewheel", function (event) { var pos = selfPointer.getHTMLElementPosition(element); @@ -509,8 +520,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ cc.eventManager.dispatchEvent(mouseEvent); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); /* firefox fix */ element.addEventListener("DOMMouseScroll", function (event) { @@ -523,8 +534,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ cc.eventManager.dispatchEvent(mouseEvent); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); } if (window.navigator.msPointerEnabled) { @@ -544,7 +555,7 @@ cc.inputManager = /** @lends cc.inputManager# */{ _touchEvent.call(selfPointer, [selfPointer.getTouchByXY(event.clientX, event.clientY, pos)]); event.stopPropagation(); - }, false); + }, supportsPassive ? { passive: true } : false); })(eventName, _pointerEventsMap[eventName]); } } @@ -559,9 +570,9 @@ cc.inputManager = /** @lends cc.inputManager# */{ pos.top -= document.body.scrollTop; selfPointer.handleTouchesBegin(selfPointer.getTouchesByEvent(event, pos)); event.stopPropagation(); - event.preventDefault(); + !supportsPassive && event.preventDefault(); element.focus(); - }, false); + }, supportsPassive ? { passive: true } : false); element.addEventListener("touchmove", function (event) { if (!event.changedTouches) return; @@ -571,8 +582,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ pos.top -= document.body.scrollTop; selfPointer.handleTouchesMove(selfPointer.getTouchesByEvent(event, pos)); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); element.addEventListener("touchend", function (event) { if (!event.changedTouches) return; @@ -582,8 +593,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ pos.top -= document.body.scrollTop; selfPointer.handleTouchesEnd(selfPointer.getTouchesByEvent(event, pos)); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); element.addEventListener("touchcancel", function (event) { if (!event.changedTouches) return; @@ -593,8 +604,8 @@ cc.inputManager = /** @lends cc.inputManager# */{ pos.top -= document.body.scrollTop; selfPointer.handleTouchesCancel(selfPointer.getTouchesByEvent(event, pos)); event.stopPropagation(); - event.preventDefault(); - }, false); + !supportsPassive && event.preventDefault(); + }, supportsPassive ? { passive: true } : false); } //register keyboard event diff --git a/package.json b/package.json new file mode 100644 index 0000000000..1a0409bd56 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "cocos2d-html", + "version": "3.16.0", + "private": true, + "description": "Cocos2d-html5", + "scripts": { + "prebuild": "rm -rf lib", + "build": "ant -f tools/build.xml" + }, + "dependencies": {}, + "devDependencies": {} +} diff --git a/template/index.html b/template/index.html deleted file mode 100644 index e0f577b927..0000000000 --- a/template/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - Cocos2d-html5 Hello World test - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/template/main.js b/template/main.js deleted file mode 100644 index b0afefa923..0000000000 --- a/template/main.js +++ /dev/null @@ -1,21 +0,0 @@ -cc.game.onStart = function(){ - if(!cc.sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it - document.body.removeChild(document.getElementById("cocosLoading")); - - var designSize = cc.size(480, 800); - var screenSize = cc.view.getFrameSize(); - - if(!cc.sys.isNative && screenSize.height < 800){ - designSize = cc.size(320, 480); - cc.loader.resPath = "res/Normal"; - }else{ - cc.loader.resPath = "res/HD"; - } - cc.view.setDesignResolutionSize(designSize.width, designSize.height, cc.ResolutionPolicy.SHOW_ALL); - - //load resources - cc.LoaderScene.preload(g_resources, function () { - cc.director.runScene(new MyScene()); - }, this); -}; -cc.game.run(); \ No newline at end of file diff --git a/template/project.json b/template/project.json deleted file mode 100644 index a4a9435aab..0000000000 --- a/template/project.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "debugMode" : 1, - "noCache": false, - "showFPS" : true, - "frameRate" : 60, - "id" : "gameCanvas", - "renderMode" : 0, - "engineDir":"../", - - "modules" : ["cocos2d"], - - "jsList" : [ - "src/resource.js", - "src/myApp.js" - ] -} \ No newline at end of file diff --git a/template/res/HD/CloseNormal.png b/template/res/HD/CloseNormal.png deleted file mode 100644 index 5657a13b58..0000000000 Binary files a/template/res/HD/CloseNormal.png and /dev/null differ diff --git a/template/res/HD/CloseSelected.png b/template/res/HD/CloseSelected.png deleted file mode 100644 index e4c82da775..0000000000 Binary files a/template/res/HD/CloseSelected.png and /dev/null differ diff --git a/template/res/HD/HelloWorld.jpg b/template/res/HD/HelloWorld.jpg deleted file mode 100644 index 1252ec6263..0000000000 Binary files a/template/res/HD/HelloWorld.jpg and /dev/null differ diff --git a/template/res/Normal/CloseNormal.png b/template/res/Normal/CloseNormal.png deleted file mode 100644 index 8c7d4ffd82..0000000000 Binary files a/template/res/Normal/CloseNormal.png and /dev/null differ diff --git a/template/res/Normal/CloseSelected.png b/template/res/Normal/CloseSelected.png deleted file mode 100644 index 25e3ab35f2..0000000000 Binary files a/template/res/Normal/CloseSelected.png and /dev/null differ diff --git a/template/res/Normal/HelloWorld.jpg b/template/res/Normal/HelloWorld.jpg deleted file mode 100644 index 76e04b56f3..0000000000 Binary files a/template/res/Normal/HelloWorld.jpg and /dev/null differ diff --git a/template/res/favicon.ico b/template/res/favicon.ico deleted file mode 100644 index 1ad6a0907b..0000000000 Binary files a/template/res/favicon.ico and /dev/null differ diff --git a/template/res/loading.js b/template/res/loading.js deleted file mode 100644 index d17a700344..0000000000 --- a/template/res/loading.js +++ /dev/null @@ -1 +0,0 @@ -(function(){var createStyle=function(){return".cocosLoading{position:absolute;margin:-30px -60px;padding:0;top:50%;left:50%}"+".cocosLoading ul{margin:0;padding:0;}"+".cocosLoading span{color:#FFF;text-align:center;display:block;}"+".cocosLoading li{list-style:none;float:left;border-radius:15px;width:15px;height:15px;background:#FFF;margin:5px 0 0 10px}"+".cocosLoading li .ball,.cocosLoading li .unball{background-color:#2187e7;background-image:-moz-linear-gradient(90deg,#2187e7 25%,#a0eaff);background-image:-webkit-linear-gradient(90deg,#2187e7 25%,#a0eaff);width:15px;height:15px;border-radius:50px}"+".cocosLoading li .ball{transform:scale(0);-moz-transform:scale(0);-webkit-transform:scale(0);animation:showDot 1s linear forwards;-moz-animation:showDot 1s linear forwards;-webkit-animation:showDot 1s linear forwards}"+".cocosLoading li .unball{transform:scale(1);-moz-transform:scale(1);-webkit-transform:scale(1);animation:hideDot 1s linear forwards;-moz-animation:hideDot 1s linear forwards;-webkit-animation:hideDot 1s linear forwards}"+"@keyframes showDot{0%{transform:scale(0,0)}100%{transform:scale(1,1)}}"+"@-moz-keyframes showDot{0%{-moz-transform:scale(0,0)}100%{-moz-transform:scale(1,1)}}"+"@-webkit-keyframes showDot{0%{-webkit-transform:scale(0,0)}100%{-webkit-transform:scale(1,1)}}"+"@keyframes hideDot{0%{transform:scale(1,1)}100%{transform:scale(0,0)}}"+"@-moz-keyframes hideDot{0%{-moz-transform:scale(1,1)}100%{-moz-transform:scale(0,0)}}"+"@-webkit-keyframes hideDot{0%{-webkit-transform:scale(1,1)}100%{-webkit-transform:scale(0,0)}}"};var createDom=function(id,num){id=id||"cocosLoading";num=num||5;var i,item;var div=document.createElement("div");div.className="cocosLoading";div.id=id;var bar=document.createElement("ul");var list=[];for(i=0;i=list.length){direction=!direction;index=0;time=1000}else{time=300}animation()},time)};animation()};(function(){var bgColor=document.body.style.background;document.body.style.background="#000";var style=document.createElement("style");style.type="text/css";style.innerHTML=createStyle();document.head.appendChild(style);var list=createDom();startAnimation(list,function(){var div=document.getElementById("cocosLoading");if(!div){document.body.style.background=bgColor}return !!div})})()})(); \ No newline at end of file diff --git a/template/src/myApp.js b/template/src/myApp.js deleted file mode 100644 index f91b7c40af..0000000000 --- a/template/src/myApp.js +++ /dev/null @@ -1,57 +0,0 @@ -var MyLayer = cc.Layer.extend({ - helloLabel:null, - sprite:null, - - init:function () { - - ////////////////////////////// - // 1. super init first - this._super(); - - ///////////////////////////// - // 2. add a menu item with "X" image, which is clicked to quit the program - // you may modify it. - // ask director the window size - var size = cc.director.getWinSize(); - - // add a "close" icon to exit the progress. it's an autorelease object - var closeItem = new cc.MenuItemImage( - s_CloseNormal, - s_CloseSelected, - function () { - cc.log("close"); - },this); - closeItem.setAnchorPoint(0.5, 0.5); - - var menu = new cc.Menu(closeItem); - menu.setPosition(0, 0); - this.addChild(menu, 1); - closeItem.setPosition(size.width - 20, 20); - - ///////////////////////////// - // 3. add your codes below... - // add a label shows "Hello World" - // create and initialize a label - this.helloLabel = new cc.LabelTTF("Hello World", "Impact", 38); - // position the label on the center of the screen - this.helloLabel.setPosition(size.width / 2, size.height - 40); - // add the label as a child to this layer - this.addChild(this.helloLabel, 5); - - // add "Helloworld" splash screen" - this.sprite = new cc.Sprite(s_HelloWorld); - this.sprite.setAnchorPoint(0.5, 0.5); - this.sprite.setPosition(size.width / 2, size.height / 2); - this.sprite.setScale(size.height / this.sprite.getContentSize().height); - this.addChild(this.sprite, 0); - } -}); - -var MyScene = cc.Scene.extend({ - onEnter:function () { - this._super(); - var layer = new MyLayer(); - this.addChild(layer); - layer.init(); - } -}); diff --git a/template/src/resource.js b/template/src/resource.js deleted file mode 100644 index 94284083d1..0000000000 --- a/template/src/resource.js +++ /dev/null @@ -1,20 +0,0 @@ -var s_HelloWorld = "HelloWorld.jpg"; -var s_CloseNormal = "CloseNormal.png"; -var s_CloseSelected = "CloseSelected.png"; - -var g_resources = [ - //image - s_HelloWorld, - s_CloseNormal, - s_CloseSelected - - //plist - - //fnt - - //tmx - - //bgm - - //effect -]; \ No newline at end of file diff --git a/tools/build.xml b/tools/build.xml index 519f9867e9..0ea601f7d4 100644 --- a/tools/build.xml +++ b/tools/build.xml @@ -1,377 +1,172 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/compiler/compiler.jar b/tools/compiler/compiler.jar index ffd565cd15..c4bca5fe29 100644 Binary files a/tools/compiler/compiler.jar and b/tools/compiler/compiler.jar differ diff --git a/tools/index.html b/tools/index.html new file mode 100644 index 0000000000..0c004f8378 --- /dev/null +++ b/tools/index.html @@ -0,0 +1,96 @@ + + + + + Cocos2d-html5 Hello World test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/main.js b/tools/main.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000000..fb57ccd13a --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +