mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Merge commit 'e248709cf2e84be9b6e56005ff15a550af230bd4'
# Conflicts: # cocos2d/core/platform/CCView.js
This commit is contained in:
@@ -796,35 +796,56 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
* @param {String} uuid - the uuid of the scene asset to load
|
||||
* @param {Function} [onLaunched]
|
||||
* @param {Function} [onUnloaded]
|
||||
* @param {Boolean} [dontRunScene] - Just download and initialize the scene but will not launch it,
|
||||
* only take effect in the Editor.
|
||||
* @private
|
||||
*/
|
||||
_loadSceneByUuid: function (uuid, onLaunched, onUnloaded) {
|
||||
_loadSceneByUuid: function (uuid, onLaunched, onUnloaded, dontRunScene) {
|
||||
if (CC_EDITOR) {
|
||||
if (typeof onLaunched === 'boolean') {
|
||||
dontRunScene = onLaunched;
|
||||
onLaunched = null;
|
||||
}
|
||||
if (typeof onUnloaded === 'boolean') {
|
||||
dontRunScene = onUnloaded;
|
||||
onUnloaded = null;
|
||||
}
|
||||
}
|
||||
//cc.AssetLibrary.unloadAsset(uuid); // force reload
|
||||
cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) {
|
||||
var self = cc.director;
|
||||
self._loadingScene = '';
|
||||
var scene;
|
||||
if (error) {
|
||||
error = 'Failed to load scene: ' + error;
|
||||
cc.error(error);
|
||||
if (CC_DEV) {
|
||||
console.assert(false, error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sceneAsset instanceof cc.SceneAsset) {
|
||||
scene = sceneAsset.scene;
|
||||
var scene = sceneAsset.scene;
|
||||
scene._id = sceneAsset._uuid;
|
||||
scene._name = sceneAsset._name;
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
if (CC_EDITOR) {
|
||||
if (!dontRunScene) {
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
else {
|
||||
scene._load();
|
||||
if (onLaunched) {
|
||||
onLaunched(null, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
error = 'The asset ' + uuid + ' is not a scene';
|
||||
cc.error(error);
|
||||
scene = null;
|
||||
}
|
||||
}
|
||||
if (error && onLaunched) {
|
||||
if (onLaunched) {
|
||||
onLaunched(error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -102,6 +102,7 @@ cc.Asset = cc.Class({
|
||||
* 在 lite 版的 Fireball 里,raw asset 并不仅仅是在 properties 里声明了 rawType 才有,
|
||||
* 而是每个 asset 都能指定自己的 raw file url。这些 url 就存在 _rawFiles 字段中。
|
||||
* AssetLibrary 并不会帮你加载这些 url,除非你声明了 rawType。
|
||||
* 在 Creator 里,_rawFiles 保留了下来,为了复用 cocos 引擎原有实现,直接用 _rawFiles 来加载 Asset 在 import 之前的源文件。
|
||||
*
|
||||
* @property _rawFiles
|
||||
* @type {String[]}
|
||||
@@ -152,8 +153,8 @@ cc.Asset = cc.Class({
|
||||
* Create a new node using this asset in the scene.<br/>
|
||||
* If this type of asset dont have its corresponding node type, this method should be null.
|
||||
* !#zh
|
||||
* 使用该资产在场景中创建一个新节点。<br/>
|
||||
* 如果这类资产没有相应的节点类型,该方法应该是空的。
|
||||
* 使用该资源在场景中创建一个新节点。<br/>
|
||||
* 如果这类资源没有相应的节点类型,该方法应该是空的。
|
||||
* @method createNode
|
||||
* @param {Function} callback
|
||||
* @param {String} callback.error - null or the error info
|
||||
@@ -170,7 +171,17 @@ cc.Asset = cc.Class({
|
||||
*/
|
||||
_setRawFiles: function (rawFiles) {
|
||||
this._rawFiles = rawFiles.length > 0 ? rawFiles : null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Preload raw files when loading scene.
|
||||
*
|
||||
* @method _preloadRawFiles
|
||||
* @param {Function} callback
|
||||
* @param {Error} callback.error
|
||||
* @private
|
||||
*/
|
||||
_preloadRawFiles: null,
|
||||
});
|
||||
|
||||
module.exports = cc.Asset;
|
||||
|
||||
@@ -46,6 +46,12 @@ var BitmapFont = cc.Class({
|
||||
fontSize: {
|
||||
default: -1
|
||||
}
|
||||
},
|
||||
|
||||
_preloadRawFiles: function (done) {
|
||||
// preload fnt file. (texture already loaded in properties)
|
||||
var fntUrl = this.rawUrl;
|
||||
cc.loader.load({ id: fntUrl, ignoreMaxConcurrency: true }, done);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -322,8 +322,10 @@ if (CC_JSB) {
|
||||
Mask.prototype.__superOnDestroy = Base.prototype.onDestroy;
|
||||
Mask.prototype.onDestroy = function () {
|
||||
this.__superOnDestroy();
|
||||
this._clippingStencil.release();
|
||||
this._clippingStencil = null;
|
||||
if (this._clippingStencil) {
|
||||
this._clippingStencil.release();
|
||||
this._clippingStencil = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
var NUMBER_OF_GATHERED_TOUCHES_FOR_MOVE_SPEED = 5;
|
||||
var OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05;
|
||||
var EPSILON = 1e-7;
|
||||
var EPSILON = 1e-4;
|
||||
var MOVEMENT_FACTOR = 0.7;
|
||||
|
||||
var quintEaseOut = function(time) {
|
||||
|
||||
@@ -695,6 +695,17 @@ cc.eventManager = {
|
||||
return a - b;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Query whether the specified event listener id has been added.
|
||||
* !#zh 查询指定的事件 ID 是否存在
|
||||
* @method hasEventListener
|
||||
* @param {String|Number} listenerID - The listener id.
|
||||
* @return {Boolean} true or false
|
||||
*/
|
||||
hasEventListener: function (listenerID) {
|
||||
return !!this._getListeners(listenerID);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* <p>
|
||||
|
||||
@@ -81,47 +81,55 @@ var SystemEvent = cc.Class({
|
||||
this._super(type, callback, target, useCapture);
|
||||
|
||||
// Keyboard
|
||||
if (!keyboardListener && (type === EventType.KEY_DOWN || type === EventType.KEY_UP)) {
|
||||
keyboardListener = cc.EventListener.create({
|
||||
event: cc.EventListener.KEYBOARD,
|
||||
onKeyPressed: function (keyCode, event) {
|
||||
event.type = EventType.KEY_DOWN;
|
||||
if (CC_JSB) {
|
||||
event.keyCode = keyCode;
|
||||
event.isPressed = true;
|
||||
if (type === EventType.KEY_DOWN || type === EventType.KEY_UP) {
|
||||
if (!keyboardListener) {
|
||||
keyboardListener = cc.EventListener.create({
|
||||
event: cc.EventListener.KEYBOARD,
|
||||
onKeyPressed: function (keyCode, event) {
|
||||
event.type = EventType.KEY_DOWN;
|
||||
if (CC_JSB) {
|
||||
event.keyCode = keyCode;
|
||||
event.isPressed = true;
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
},
|
||||
onKeyReleased: function (keyCode, event) {
|
||||
event.type = EventType.KEY_UP;
|
||||
if (CC_JSB) {
|
||||
event.keyCode = keyCode;
|
||||
event.isPressed = false;
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
},
|
||||
onKeyReleased: function (keyCode, event) {
|
||||
event.type = EventType.KEY_UP;
|
||||
if (CC_JSB) {
|
||||
event.keyCode = keyCode;
|
||||
event.isPressed = false;
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
cc.eventManager.addListener(keyboardListener, 1);
|
||||
});
|
||||
}
|
||||
if (!cc.eventManager.hasEventListener(cc._EventListenerKeyboard.LISTENER_ID)) {
|
||||
cc.eventManager.addListener(keyboardListener, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Acceleration
|
||||
if (!accelerationListener && type === EventType.DEVICEMOTION) {
|
||||
accelerationListener = cc.EventListener.create({
|
||||
event: cc.EventListener.ACCELERATION,
|
||||
callback: function (accelEvent, event) {
|
||||
event.type = EventType.DEVICEMOTION;
|
||||
// fix android acc values are opposite
|
||||
if (!CC_JSB && cc.sys.os === cc.sys.OS_ANDROID &&
|
||||
cc.sys.browserType !== cc.sys.BROWSER_TYPE_MOBILE_QQ) {
|
||||
event.acc = cc.p(-accelEvent.x, -accelEvent.y);
|
||||
if (type === EventType.DEVICEMOTION) {
|
||||
if (accelerationListener) {
|
||||
accelerationListener = cc.EventListener.create({
|
||||
event: cc.EventListener.ACCELERATION,
|
||||
callback: function (accelEvent, event) {
|
||||
event.type = EventType.DEVICEMOTION;
|
||||
// fix android acc values are opposite
|
||||
if (!CC_JSB && cc.sys.os === cc.sys.OS_ANDROID &&
|
||||
cc.sys.browserType !== cc.sys.BROWSER_TYPE_MOBILE_QQ) {
|
||||
event.acc = cc.p(-accelEvent.x, -accelEvent.y);
|
||||
}
|
||||
else {
|
||||
event.acc = cc.p(accelEvent.x, accelEvent.y);
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
}
|
||||
else {
|
||||
event.acc = cc.p(accelEvent.x, accelEvent.y);
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
cc.eventManager.addListener(accelerationListener, 1);
|
||||
});
|
||||
}
|
||||
if (!cc.eventManager.hasEventListener(cc._EventListenerAcceleration.LISTENER_ID)) {
|
||||
cc.eventManager.addListener(accelerationListener, 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1140,8 +1140,8 @@ cc.BMFontHelper = {
|
||||
_setBMFontFile: function(filename, textureUrl) {
|
||||
if (filename) {
|
||||
this._fontHandle = filename;
|
||||
var self = this;
|
||||
if (this._labelType === _ccsg.Label.Type.BMFont) {
|
||||
var self = this;
|
||||
this._resetBMFont();
|
||||
|
||||
cc.loader.load(this._fontHandle, function(err, config) {
|
||||
|
||||
@@ -92,6 +92,15 @@ function loadDepends (pipeline, item, asset, tdInfo, deferredLoadRawAssetsInRunt
|
||||
propList.push(tdInfo.rawProp);
|
||||
depends.push(item.url);
|
||||
}
|
||||
// preload raw files
|
||||
if (asset._preloadRawFiles) {
|
||||
var finalCallback = callback;
|
||||
callback = function () {
|
||||
asset._preloadRawFiles(function (err) {
|
||||
finalCallback(err || null, asset);
|
||||
});
|
||||
};
|
||||
}
|
||||
// fast path
|
||||
if (depends.length === 0) {
|
||||
asset._uuid = uuid;
|
||||
|
||||
@@ -42,7 +42,7 @@ var TYPO_TO_CORRECT = CC_DEV && {
|
||||
constructor: 'ctor'
|
||||
};
|
||||
|
||||
var INVALID_STATICS = CC_DEV && ['name', '__ctors__', '__props__', 'arguments', 'call', 'apply', 'caller',
|
||||
var INVALID_STATICS_DEV = CC_DEV && ['name', '__ctors__', '__props__', 'arguments', 'call', 'apply', 'caller',
|
||||
'length', 'prototype'];
|
||||
|
||||
var deferredInitializer = {
|
||||
@@ -305,7 +305,7 @@ function doDefine (className, baseClass, mixins, constructor, options) {
|
||||
|
||||
// mixin statics (this will also copy editor attributes for component)
|
||||
for (var p in mixin)
|
||||
if (mixin.hasOwnProperty(p) && INVALID_STATICS.indexOf(p) < 0)
|
||||
if (mixin.hasOwnProperty(p) && (!CC_DEV || INVALID_STATICS_DEV.indexOf(p) < 0))
|
||||
fireClass[p] = mixin[p];
|
||||
|
||||
// mixin attributes
|
||||
@@ -832,7 +832,7 @@ function CCClass (options) {
|
||||
var staticPropName;
|
||||
if (CC_DEV) {
|
||||
for (staticPropName in statics) {
|
||||
if (INVALID_STATICS.indexOf(staticPropName) !== -1) {
|
||||
if (INVALID_STATICS_DEV.indexOf(staticPropName) !== -1) {
|
||||
cc.error('Cannot define %s.%s because static member name can not be "%s".', name, staticPropName,
|
||||
staticPropName);
|
||||
}
|
||||
|
||||
@@ -442,9 +442,9 @@ var View = cc._Class.extend({
|
||||
}
|
||||
this._antiAliasEnabled = enabled;
|
||||
if(cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
|
||||
var map = cc.loader._cache;
|
||||
for (var key in map) {
|
||||
var item = map[key];
|
||||
var cache = cc.loader._cache;
|
||||
for (var key in cache) {
|
||||
var item = cache[key];
|
||||
var tex = item && item.content instanceof cc.Texture2D ? item.content : null;
|
||||
if (tex) {
|
||||
if (enabled) {
|
||||
|
||||
@@ -790,12 +790,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
},
|
||||
|
||||
_onPreDestroy: function () {
|
||||
cc.eventManager.removeListeners(this);
|
||||
if (CC_JSB) {
|
||||
this._sgNode.release();
|
||||
this._sgNode._entity = null;
|
||||
this._sgNode = null;
|
||||
}
|
||||
cc.eventManager.removeListeners(this);
|
||||
for (var i = 0, len = this.__eventTargets.length; i < len; ++i) {
|
||||
var target = this.__eventTargets[i];
|
||||
target && target.targetOff(this);
|
||||
|
||||
@@ -918,6 +918,10 @@ var ParticleSystem = cc.Class({
|
||||
// so use the texutreUuid instead of textureImageData
|
||||
if (content.textureUuid) {
|
||||
cc.AssetLibrary.queryAssetInfo(content.textureUuid, function (err, url, raw) {
|
||||
if (err) {
|
||||
cc.error(err);
|
||||
return;
|
||||
}
|
||||
self.texture = url;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1339,8 +1339,10 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
locModeA.tangentialAccelVar = (pszTmp) ? parseFloat(pszTmp) : 0;
|
||||
|
||||
// rotation is dir
|
||||
var locRotationIsDir = locValueForKey("rotationIsDir", dictionary).toLowerCase();
|
||||
locModeA.rotationIsDir = (locRotationIsDir != null && (locRotationIsDir === "true" || locRotationIsDir === "1"));
|
||||
var locRotationIsDir = locValueForKey("rotationIsDir", dictionary);
|
||||
locRotationIsDir = ("" + locRotationIsDir).toLowerCase();
|
||||
locModeA.rotationIsDir = (locRotationIsDir === "true" || locRotationIsDir === "1");
|
||||
|
||||
} else if (this.emitterMode === _ccsg.ParticleSystem.Mode.RADIUS) {
|
||||
// or Mode B: radius movement
|
||||
var locModeB = this.modeB;
|
||||
|
||||
+30
-9
@@ -328,35 +328,56 @@ cc.js.mixin(cc.director, {
|
||||
* @param {String} uuid - the uuid of the scene asset to load
|
||||
* @param {Function} [onLaunched]
|
||||
* @param {Function} [onUnloaded]
|
||||
* @param {Boolean} [dontRunScene] - Just download and initialize the scene but will not launch it,
|
||||
* only take effect in the Editor.
|
||||
* @private
|
||||
*/
|
||||
_loadSceneByUuid: function (uuid, onLaunched, onUnloaded) {
|
||||
_loadSceneByUuid: function (uuid, onLaunched, onUnloaded, dontRunScene) {
|
||||
if (CC_EDITOR) {
|
||||
if (typeof onLaunched === 'boolean') {
|
||||
dontRunScene = onLaunched;
|
||||
onLaunched = null;
|
||||
}
|
||||
if (typeof onUnloaded === 'boolean') {
|
||||
dontRunScene = onUnloaded;
|
||||
onUnloaded = null;
|
||||
}
|
||||
}
|
||||
//cc.AssetLibrary.unloadAsset(uuid); // force reload
|
||||
cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) {
|
||||
var self = cc.director;
|
||||
self._loadingScene = '';
|
||||
var scene;
|
||||
if (error) {
|
||||
error = 'Failed to load scene: ' + error;
|
||||
cc.error(error);
|
||||
if (CC_DEV) {
|
||||
console.assert(false, error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sceneAsset instanceof cc.SceneAsset) {
|
||||
scene = sceneAsset.scene;
|
||||
var scene = sceneAsset.scene;
|
||||
scene._id = sceneAsset._uuid;
|
||||
scene._name = sceneAsset._name;
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
if (CC_EDITOR) {
|
||||
if (!dontRunScene) {
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
else {
|
||||
scene._load();
|
||||
if (onLaunched) {
|
||||
onLaunched(null, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
error = 'The asset ' + uuid + ' is not a scene';
|
||||
cc.error(error);
|
||||
scene = null;
|
||||
}
|
||||
}
|
||||
if (error && onLaunched) {
|
||||
if (onLaunched) {
|
||||
onLaunched(error);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user