mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 11:31:59 +08:00
Merge remote:master
This commit is contained in:
@@ -58,7 +58,7 @@ _p = null;
|
||||
* @name cc.ENGINE_VERSION
|
||||
*/
|
||||
var engineVersion;
|
||||
engineVersion = '1.2.0-rc.2';
|
||||
engineVersion = '1.2.1-beta.4';
|
||||
window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion;
|
||||
|
||||
/**
|
||||
|
||||
+13
-7
@@ -451,8 +451,8 @@ cc._initDebugSetting = function (mode) {
|
||||
* - 在 Chrome 中,错误信息有红色的图标以及红色的消息文本。<br/>
|
||||
*
|
||||
* @method error
|
||||
* @param {Any} obj - A JavaScript string containing zero or more substitution strings.
|
||||
* @param {Any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
* @param {any} obj - A JavaScript string containing zero or more substitution strings.
|
||||
* @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
*/
|
||||
if (CC_EDITOR) {
|
||||
cc.error = Editor.error;
|
||||
@@ -484,8 +484,8 @@ cc._initDebugSetting = function (mode) {
|
||||
* - 在 Cocos Creator 中,警告信息显示是黄色的。<br/>
|
||||
* - 在 Chrome 中,警告信息有着黄色的图标以及黄色的消息文本。<br/>
|
||||
* @method warn
|
||||
* @param {Any} obj - A JavaScript string containing zero or more substitution strings.
|
||||
* @param {Any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
* @param {any} obj - A JavaScript string containing zero or more substitution strings.
|
||||
* @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
*/
|
||||
if (CC_EDITOR) {
|
||||
cc.warn = Editor.warn;
|
||||
@@ -509,8 +509,8 @@ cc._initDebugSetting = function (mode) {
|
||||
* !#en Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime).
|
||||
* !#zh 输出一条消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。
|
||||
* @method log
|
||||
* @param {Any} obj - A JavaScript string containing zero or more substitution strings.
|
||||
* @param {Any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
* @param {any} obj - A JavaScript string containing zero or more substitution strings.
|
||||
* @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
|
||||
*/
|
||||
if (CC_JSB) {
|
||||
cc.log = jsbLog;
|
||||
@@ -543,7 +543,13 @@ cc._initDebugSetting = function (mode) {
|
||||
}
|
||||
}
|
||||
cc._throw = CC_EDITOR ? Editor.error : function (error) {
|
||||
cc.error(error.stack || error);
|
||||
var stack = error.stack;
|
||||
if (stack) {
|
||||
cc.error(CC_JSB ? (error + '\n' + stack) : stack);
|
||||
}
|
||||
else {
|
||||
cc.error(error);
|
||||
}
|
||||
};
|
||||
};
|
||||
//+++++++++++++++++++++++++something about log end+++++++++++++++++++++++++++++
|
||||
|
||||
@@ -69,36 +69,6 @@ cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
|
||||
return cc.p(x, y);
|
||||
};
|
||||
|
||||
/*
|
||||
* returns a new copy of the array reversed.
|
||||
* @method reverseControlPoints
|
||||
* @param {Array} controlPoints
|
||||
* @return {Array}
|
||||
*/
|
||||
cc.reverseControlPoints = function (controlPoints) {
|
||||
var newArray = [];
|
||||
for (var i = controlPoints.length - 1; i >= 0; i--) {
|
||||
newArray.push(cc.p(controlPoints[i].x, controlPoints[i].y));
|
||||
}
|
||||
return newArray;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* returns a new clone of the controlPoints
|
||||
* @method cloneControlPoints
|
||||
* @param {Array} controlPoints
|
||||
* @returns {Array}
|
||||
*/
|
||||
cc.cloneControlPoints = function (controlPoints) {
|
||||
var newArray = [];
|
||||
for (var i = 0; i < controlPoints.length; i++)
|
||||
newArray.push(cc.p(controlPoints[i].x, controlPoints[i].y));
|
||||
return newArray;
|
||||
};
|
||||
|
||||
cc.copyControlPoints = cc.cloneControlPoints;
|
||||
|
||||
/*
|
||||
* returns a point from the array
|
||||
* @method getControlPointAt
|
||||
@@ -111,20 +81,20 @@ cc.getControlPointAt = function (controlPoints, pos) {
|
||||
return controlPoints[p];
|
||||
};
|
||||
|
||||
/*
|
||||
* reverse the current control point array inline, without generating a new one <br />
|
||||
* @method reverseControlPointsInline
|
||||
* @param {Array} controlPoints
|
||||
*/
|
||||
cc.reverseControlPointsInline = function (controlPoints) {
|
||||
var len = controlPoints.length;
|
||||
var mid = 0 | (len / 2);
|
||||
for (var i = 0; i < mid; ++i) {
|
||||
var temp = controlPoints[i];
|
||||
controlPoints[i] = controlPoints[len - i - 1];
|
||||
controlPoints[len - i - 1] = temp;
|
||||
function reverseControlPoints (controlPoints) {
|
||||
var newArray = [];
|
||||
for (var i = controlPoints.length - 1; i >= 0; i--) {
|
||||
newArray.push(cc.p(controlPoints[i].x, controlPoints[i].y));
|
||||
}
|
||||
};
|
||||
return newArray;
|
||||
}
|
||||
|
||||
function cloneControlPoints (controlPoints) {
|
||||
var newArray = [];
|
||||
for (var i = 0; i < controlPoints.length; i++)
|
||||
newArray.push(cc.p(controlPoints[i].x, controlPoints[i].y));
|
||||
return newArray;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -157,15 +127,6 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
|
||||
tension !== undefined && this.initWithDuration(duration, points, tension);
|
||||
},
|
||||
|
||||
/*
|
||||
* initializes the action with a duration and an array of points
|
||||
* @method initWithDuration
|
||||
* @param {Number} duration
|
||||
* @param {Array} points array of control points
|
||||
* @param {Number} tension
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
initWithDuration:function (duration, points, tension) {
|
||||
if(!points || points.length === 0)
|
||||
throw new Error("Invalid configuration. It must at least have one control point");
|
||||
@@ -180,7 +141,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
|
||||
|
||||
clone:function () {
|
||||
var action = new cc.CardinalSplineTo();
|
||||
action.initWithDuration(this._duration, cc.copyControlPoints(this._points), this._tension);
|
||||
action.initWithDuration(this._duration, cloneControlPoints(this._points), this._tension);
|
||||
return action;
|
||||
},
|
||||
|
||||
@@ -234,7 +195,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
var reversePoints = cc.reverseControlPoints(this._points);
|
||||
var reversePoints = reverseControlPoints(this._points);
|
||||
return cc.cardinalSplineTo(this._duration, reversePoints, this._tension);
|
||||
},
|
||||
|
||||
@@ -257,7 +218,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
|
||||
return this._points;
|
||||
},
|
||||
|
||||
/*
|
||||
/**
|
||||
* Points setter
|
||||
* @method setPoints
|
||||
* @param {Array} points
|
||||
@@ -329,7 +290,7 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
|
||||
}
|
||||
|
||||
// convert to "diffs" to "reverse absolute"
|
||||
var reverseArray = cc.reverseControlPoints(copyConfig);
|
||||
var reverseArray = reverseControlPoints(copyConfig);
|
||||
|
||||
// 1st element (which should be 0,0) should be here too
|
||||
p = reverseArray[ reverseArray.length - 1 ];
|
||||
@@ -351,7 +312,7 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
|
||||
return cc.cardinalSplineBy(this._duration, reverseArray, this._tension);
|
||||
},
|
||||
|
||||
/*
|
||||
/**
|
||||
* update position of target
|
||||
* @method updatePosition
|
||||
* @param {Vec2} newPos
|
||||
@@ -365,14 +326,9 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
|
||||
this.target.setPosition(posX, posY);
|
||||
},
|
||||
|
||||
/*
|
||||
* returns a new clone of the action
|
||||
* @method clone
|
||||
* @returns {CardinalSplineBy}
|
||||
*/
|
||||
clone:function () {
|
||||
var a = new cc.CardinalSplineBy();
|
||||
a.initWithDuration(this._duration, cc.copyControlPoints(this._points), this._tension);
|
||||
a.initWithDuration(this._duration, cloneControlPoints(this._points), this._tension);
|
||||
return a;
|
||||
}
|
||||
});
|
||||
@@ -412,19 +368,13 @@ cc.CatmullRomTo = cc.CardinalSplineTo.extend({
|
||||
points && this.initWithDuration(dt, points);
|
||||
},
|
||||
|
||||
/*
|
||||
* Initializes the action with a duration and an array of points
|
||||
* @method initWithDuration
|
||||
* @param {Number} dt
|
||||
* @param {Array} points
|
||||
*/
|
||||
initWithDuration:function (dt, points) {
|
||||
return cc.CardinalSplineTo.prototype.initWithDuration.call(this, dt, points, 0.5);
|
||||
},
|
||||
|
||||
clone:function () {
|
||||
var action = new cc.CatmullRomTo();
|
||||
action.initWithDuration(this._duration, cc.copyControlPoints(this._points));
|
||||
action.initWithDuration(this._duration, cloneControlPoints(this._points));
|
||||
return action;
|
||||
}
|
||||
});
|
||||
@@ -466,20 +416,13 @@ cc.CatmullRomBy = cc.CardinalSplineBy.extend({
|
||||
points && this.initWithDuration(dt, points);
|
||||
},
|
||||
|
||||
/*
|
||||
* initializes the action with a duration and an array of points
|
||||
*
|
||||
* @method initWithDuration
|
||||
* @param {Number} dt
|
||||
* @param {Array} points
|
||||
*/
|
||||
initWithDuration:function (dt, points) {
|
||||
return cc.CardinalSplineTo.prototype.initWithDuration.call(this, dt, points, 0.5);
|
||||
},
|
||||
|
||||
clone:function () {
|
||||
var action = new cc.CatmullRomBy();
|
||||
action.initWithDuration(this._duration, cc.copyControlPoints(this._points));
|
||||
action.initWithDuration(this._duration, cloneControlPoints(this._points));
|
||||
return action;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
*
|
||||
* @class ActionTweenDelegate
|
||||
* @extends _Class
|
||||
*/
|
||||
cc.ActionTweenDelegate = cc._Class.extend(/** @lends cc.ActionTweenDelegate */{
|
||||
|
||||
/**
|
||||
* Update Tween Action.
|
||||
* @param value
|
||||
* @param key
|
||||
*/
|
||||
updateTweenAction:function(value, key){}
|
||||
});
|
||||
|
||||
/**
|
||||
* cc.ActionTween
|
||||
* cc.ActionTween is an action that lets you update any property of an object.
|
||||
*
|
||||
* @class
|
||||
* @extends ActionInterval
|
||||
* @example
|
||||
* //For example, if you want to modify the "width" property of a target from 200 to 300 in 2 seconds, then:
|
||||
* var modifyWidth = cc.actionTween(2,"width",200,300)
|
||||
* target.runAction(modifyWidth);
|
||||
*
|
||||
* //Another example: cc.ScaleTo action could be rewriten using cc.PropertyAction:
|
||||
* // scaleA and scaleB are equivalents
|
||||
* var scaleA = cc.scaleTo(2,3);
|
||||
* var scaleB = cc.actionTween(2,"scale",1,3);
|
||||
* @param {Number} duration
|
||||
* @param {String} key
|
||||
* @param {Number} from
|
||||
* @param {Number} to
|
||||
*/
|
||||
cc.ActionTween = cc.ActionInterval.extend(/** @lends cc.ActionTween */{
|
||||
key:"",
|
||||
from:0,
|
||||
to:0,
|
||||
delta:0,
|
||||
|
||||
/**
|
||||
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
|
||||
* Creates an initializes the action with the property name (key), and the from and to parameters.
|
||||
* @param {Number} duration
|
||||
* @param {String} key
|
||||
* @param {Number} from
|
||||
* @param {Number} to
|
||||
*/
|
||||
ctor:function(duration, key, from, to){
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this.key = "";
|
||||
|
||||
to !== undefined && this.initWithDuration(duration, key, from, to);
|
||||
},
|
||||
|
||||
/**
|
||||
* initializes the action with the property name (key), and the from and to parameters.
|
||||
* @param {Number} duration
|
||||
* @param {String} key
|
||||
* @param {Number} from
|
||||
* @param {Number} to
|
||||
* @return {Boolean}
|
||||
*/
|
||||
initWithDuration:function (duration, key, from, to) {
|
||||
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
|
||||
this.key = key;
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Start this tween with target.
|
||||
* @param {ActionTweenDelegate} target
|
||||
*/
|
||||
startWithTarget:function (target) {
|
||||
if(!target || !target.updateTweenAction)
|
||||
throw new Error("cc.ActionTween.startWithTarget(): target must be non-null, and target must implement updateTweenAction function");
|
||||
cc.ActionInterval.prototype.startWithTarget.call(this, target);
|
||||
this.delta = this.to - this.from;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called once per frame. Time is the number of seconds of a frame interval.
|
||||
*
|
||||
* @param {Number} dt
|
||||
*/
|
||||
update:function (dt) {
|
||||
this.target.updateTweenAction(this.to - this.delta * (1 - dt), this.key);
|
||||
},
|
||||
|
||||
/**
|
||||
* returns a reversed action.
|
||||
* @return {ActionTween}
|
||||
*/
|
||||
reverse:function () {
|
||||
return new cc.ActionTween(this.duration, this.key, this.to, this.from);
|
||||
},
|
||||
|
||||
/**
|
||||
* to copy object with deep copy.
|
||||
* returns a clone of action.
|
||||
*
|
||||
* @return {ActionTween}
|
||||
*/
|
||||
clone:function(){
|
||||
var action = new cc.ActionTween();
|
||||
action.initWithDuration(this._duration, this.key, this.from, this.to);
|
||||
return action;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates an initializes the action with the property name (key), and the from and to parameters.
|
||||
* @method
|
||||
* @param {Number} duration
|
||||
* @param {String} key
|
||||
* @param {Number} from
|
||||
* @param {Number} to
|
||||
* @return {ActionTween}
|
||||
*/
|
||||
cc.actionTween = function (duration, key, from, to) {
|
||||
return new cc.ActionTween(duration, key, from, to);
|
||||
};
|
||||
|
||||
/**
|
||||
* Please use cc.actionTween instead.
|
||||
* Creates an initializes the action with the property name (key), and the from and to parameters.
|
||||
* @static
|
||||
* @deprecated since v3.0 <br /> Please use cc.actionTween instead.
|
||||
* @param {Number} duration
|
||||
* @param {String} key
|
||||
* @param {Number} from
|
||||
* @param {Number} to
|
||||
* @return {ActionTween}
|
||||
*/
|
||||
cc.ActionTween.create = cc.actionTween;
|
||||
@@ -1,4 +1,5 @@
|
||||
require('./CCAction.js');
|
||||
require('./CCActionInterval.js');
|
||||
require('./CCActionInstant.js');
|
||||
require('./CCActionEase.js');
|
||||
require('./CCActionEase.js');
|
||||
require('./CCActionCatmullRom.js');
|
||||
@@ -86,7 +86,7 @@ var AnimationClip = cc.Class({
|
||||
* !#en Crate clip with a set of sprite frames
|
||||
* !#zh 使用一组序列帧图片来创建动画剪辑
|
||||
* @method createWithSpriteFrames
|
||||
* @param {[cc.SpriteFrame]} spriteFrames
|
||||
* @param {[SpriteFrame]} spriteFrames
|
||||
* @param {Number} sample
|
||||
* @return {AnimationClip}
|
||||
* @example
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
var EventTarget = require('./event/event-target');
|
||||
var Class = require('./platform/_CCClass');
|
||||
var AutoReleaseUtils = require('./load-pipeline/auto-release-utils');
|
||||
|
||||
cc.g_NumberOfDraws = 0;
|
||||
|
||||
@@ -389,8 +390,12 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
getZEye: null,
|
||||
|
||||
/**
|
||||
* !#en Pause the director's ticker.
|
||||
* !#zh 暂停正在运行的场景,该暂停只会停止 Scheduler,但是不会停止渲染和 UI 响应。
|
||||
* !#en Pause the director's ticker, only involve the game logic execution.
|
||||
* It won't pause the rendering process nor the event manager.
|
||||
* If you want to pause the entier game including rendering, audio and event,
|
||||
* please use {{#crossLink "Game.pause"}}cc.game.pause{{/crossLink}}
|
||||
* !#zh 暂停正在运行的场景,该暂停只会停止游戏逻辑执行,但是不会停止渲染和 UI 响应。
|
||||
* 如果想要更彻底得暂停游戏,包含渲染,音频和事件,请使用 {{#crossLink "Game.pause"}}cc.game.pause{{/crossLink}}。
|
||||
* @method pause
|
||||
*/
|
||||
pause: function () {
|
||||
@@ -536,8 +541,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
var persistNodes = game._persistRootNodes;
|
||||
|
||||
if (scene instanceof cc.Scene) {
|
||||
// ensure scene initialized
|
||||
scene._load();
|
||||
scene._load(); // ensure scene initialized
|
||||
}
|
||||
|
||||
// detach persist nodes
|
||||
@@ -548,8 +552,13 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
game._ignoreRemovePersistNode = null;
|
||||
}
|
||||
|
||||
// unload scene
|
||||
var oldScene = this._scene;
|
||||
|
||||
// auto release assets
|
||||
var autoReleaseAssets = oldScene && oldScene.autoReleaseAssets && oldScene.dependAssets;
|
||||
AutoReleaseUtils.autoRelease(cc.loader, autoReleaseAssets, scene.dependAssets);
|
||||
|
||||
// unload scene
|
||||
if (cc.isValid(oldScene)) {
|
||||
oldScene.destroy();
|
||||
}
|
||||
@@ -818,8 +827,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Resume director after pause, if the current scene is not paused, nothing will happen.
|
||||
* !#zh 恢复暂停场景,恢复 Scheduler,如果当前场景没有暂停将没任何事情发生。
|
||||
* !#en Resume game logic execution after pause, if the current scene is not paused, nothing will happen.
|
||||
* !#zh 恢复暂停场景的游戏逻辑,如果当前场景没有暂停将没任何事情发生。
|
||||
* @method resume
|
||||
*/
|
||||
resume: function () {
|
||||
|
||||
+25
-10
@@ -29,17 +29,19 @@ if (!(CC_EDITOR && Editor.isMainProcess)) {
|
||||
View = require('./platform/CCView');
|
||||
}
|
||||
|
||||
var _isMusicPlaying = false;
|
||||
|
||||
/**
|
||||
* !#en An object to boot the game.
|
||||
* !#zh 包含游戏主体信息并负责驱动游戏的游戏对象。
|
||||
* @class Game
|
||||
*/
|
||||
var game = /** @lends cc.game# */{
|
||||
var game = {
|
||||
|
||||
/**
|
||||
* Event triggered when game hide to background.
|
||||
* Please note that this event is not 100% guaranteed to be fired.
|
||||
* @property
|
||||
* @property EVENT_HIDE
|
||||
* @type {String}
|
||||
* @example
|
||||
* cc.game.on(cc.game.EVENT_HIDE, function () {
|
||||
@@ -52,21 +54,21 @@ var game = /** @lends cc.game# */{
|
||||
/**
|
||||
* Event triggered when game back to foreground
|
||||
* Please note that this event is not 100% guaranteed to be fired.
|
||||
* @property
|
||||
* @property EVENT_SHOW
|
||||
* @type {String}
|
||||
*/
|
||||
EVENT_SHOW: "game_on_show",
|
||||
|
||||
/**
|
||||
* Event triggered after game inited, at this point all engine objects and game scripts are loaded
|
||||
* @property
|
||||
* @property EVENT_GAME_INITED
|
||||
* @type {String}
|
||||
*/
|
||||
EVENT_GAME_INITED: "game_inited",
|
||||
|
||||
/**
|
||||
* Event triggered after renderer inited, at this point you will be able to use the render context
|
||||
* @property
|
||||
* @property EVENT_RENDERER_INITED
|
||||
* @type {String}
|
||||
*/
|
||||
EVENT_RENDERER_INITED: "renderer_inited",
|
||||
@@ -80,7 +82,7 @@ var game = /** @lends cc.game# */{
|
||||
|
||||
/**
|
||||
* Key of config
|
||||
* @property
|
||||
* @property CONFIG_KEY
|
||||
* @type {Object}
|
||||
*/
|
||||
CONFIG_KEY: {
|
||||
@@ -241,8 +243,10 @@ var game = /** @lends cc.game# */{
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Pause the game,pause main loop.
|
||||
* !#zh 暂停游戏,暂停的是整个主循环。
|
||||
* !#en Pause the game main loop. This will pause:
|
||||
* game logic execution, rendering process, event manager, background music and all audio effects.
|
||||
* This is different with cc.director.pause which only pause the game logic execution.
|
||||
* !#zh 暂停游戏主循环。包含:游戏逻辑,渲染,事件处理,背景音乐和所有音效。这点和只暂停游戏逻辑的 cc.director.pause 不同。
|
||||
* @method pause
|
||||
*/
|
||||
pause: function () {
|
||||
@@ -250,6 +254,11 @@ var game = /** @lends cc.game# */{
|
||||
this._paused = true;
|
||||
// Pause audio engine
|
||||
cc.audioEngine && cc.audioEngine.pauseAll();
|
||||
// Pause event
|
||||
var scene = cc.director.getScene() || cc.director.getRunningScene();
|
||||
if (scene) {
|
||||
cc.eventManager.pauseTarget(scene, true);
|
||||
}
|
||||
// Pause main loop
|
||||
if (this._intervalId)
|
||||
window.cancelAnimationFrame(this._intervalId);
|
||||
@@ -257,8 +266,9 @@ var game = /** @lends cc.game# */{
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Resume the game from pause.
|
||||
* !#zh 继续游戏,继续的是整个主循环。
|
||||
* !#en Resume the game from pause. This will resume:
|
||||
* game logic execution, rendering process, event manager, background music and all audio effects.
|
||||
* !#zh 恢复游戏主循环。包含:游戏逻辑,渲染,事件处理,背景音乐和所有音效。
|
||||
* @method resume
|
||||
*/
|
||||
resume: function () {
|
||||
@@ -266,6 +276,11 @@ var game = /** @lends cc.game# */{
|
||||
this._paused = false;
|
||||
// Resume audio engine
|
||||
cc.audioEngine && cc.audioEngine.resumeAll();
|
||||
// Resume event
|
||||
var scene = cc.director.getScene() || cc.director.getRunningScene();
|
||||
if (scene) {
|
||||
cc.eventManager.resumeTarget(scene, true);
|
||||
}
|
||||
// Resume main loop
|
||||
this._runMainLoop();
|
||||
},
|
||||
|
||||
+19
-3
@@ -527,6 +527,11 @@ var Node = cc.Class({
|
||||
this.stopAllActions();
|
||||
this._releaseAllActions();
|
||||
|
||||
// Remove Node.currentHovered
|
||||
if (currentHovered === this) {
|
||||
currentHovered = null;
|
||||
}
|
||||
|
||||
// Remove all listeners
|
||||
if (CC_JSB && this._touchListener) {
|
||||
this._touchListener.release();
|
||||
@@ -964,6 +969,12 @@ var Node = cc.Class({
|
||||
// activate
|
||||
cc.director.getActionManager().resumeTarget(this);
|
||||
cc.eventManager.resumeTarget(this);
|
||||
if (this._touchListener) {
|
||||
this._touchListener.mask = _searchMaskParent(this);
|
||||
}
|
||||
if (this._mouseListener) {
|
||||
this._mouseListener.mask = _searchMaskParent(this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// deactivate
|
||||
@@ -1264,17 +1275,22 @@ var Node = cc.Class({
|
||||
/**
|
||||
* !#en
|
||||
* Executes an action, and returns the action that is executed.<br/>
|
||||
* The node becomes the action's target. Refer to cc.Action's getTarget()<br/>
|
||||
* Calling runAction while the node is not active won't have any effect.
|
||||
* The node becomes the action's target. Refer to cc.Action's getTarget() <br/>
|
||||
* Calling runAction while the node is not active won't have any effect. <br/>
|
||||
* Note:You shouldn't modify the action after runAction, that won't take any effect.<br/>
|
||||
* if you want to modify, when you define action plus.
|
||||
* !#zh
|
||||
* 执行并返回该执行的动作。该节点将会变成动作的目标。<br/>
|
||||
* 调用 runAction 时,节点自身处于不激活状态将不会有任何效果。
|
||||
* 调用 runAction 时,节点自身处于不激活状态将不会有任何效果。<br/>
|
||||
* 注意:你不应该修改 runAction 后的动作,将无法发挥作用,如果想进行修改,请在定义 action 时加入。
|
||||
* @method runAction
|
||||
* @param {Action} action
|
||||
* @return {Action} An Action pointer
|
||||
* @example
|
||||
* var action = cc.scaleTo(0.2, 1, 0.6);
|
||||
* node.runAction(action);
|
||||
* node.runAction(action).repeatForever(); // fail
|
||||
* node.runAction(action.repeatForever()); // right
|
||||
*/
|
||||
runAction: function (action) {
|
||||
if (!this.active)
|
||||
|
||||
+14
-46
@@ -38,15 +38,17 @@ cc.Scene = cc.Class({
|
||||
name: 'cc.Scene',
|
||||
extends: require('./utils/base-node'),
|
||||
|
||||
//properties: {
|
||||
// /**
|
||||
// * !#en Indicates the raw assets of this scene can be load after scene launched.
|
||||
// * !#zh 指示该场景依赖的资源可否在场景切换后再延迟加载。
|
||||
// * @property {Boolean} _asyncLoadAssets
|
||||
// * @default false
|
||||
// */
|
||||
// _asyncLoadAssets: false
|
||||
//},
|
||||
properties: {
|
||||
|
||||
/**
|
||||
* !#en Indicates whether all (directly or indirectly) static referenced assets of this scene are releasable by default after scene unloading.
|
||||
* !#zh 指示该场景中直接或间接静态引用到的所有资源是否默认在场景切换后自动释放。
|
||||
* @property {Boolean} autoReleaseAssets
|
||||
* @default false
|
||||
*/
|
||||
autoReleaseAssets: undefined,
|
||||
|
||||
},
|
||||
|
||||
ctor: function () {
|
||||
var sgNode = this._sgNode = new _ccsg.Scene();
|
||||
@@ -59,6 +61,9 @@ cc.Scene = cc.Class({
|
||||
|
||||
this._activeInHierarchy = false;
|
||||
this._inited = !cc.game._isCloning;
|
||||
|
||||
// cache all depend assets for auto release
|
||||
this.dependAssets = null;
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
@@ -112,40 +117,3 @@ cc.Scene = cc.Class({
|
||||
});
|
||||
|
||||
module.exports = cc.Scene;
|
||||
|
||||
if (CC_DEV) {
|
||||
var ERR = '"%s" is not defined in the Scene, it is only defined in child nodes.';
|
||||
Object.defineProperties(cc.Scene.prototype, {
|
||||
active: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'active');
|
||||
return true;
|
||||
},
|
||||
set: function () {
|
||||
cc.error(ERR, 'active');
|
||||
}
|
||||
},
|
||||
activeInHierarchy: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'activeInHierarchy');
|
||||
return true;
|
||||
},
|
||||
},
|
||||
getComponent: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'getComponent');
|
||||
return function () {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
},
|
||||
addComponent: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'addComponent');
|
||||
return function () {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -35,14 +35,27 @@ var Scene = cc.Class({
|
||||
extends: cc.Asset,
|
||||
|
||||
properties: {
|
||||
|
||||
/**
|
||||
* @property {cc.Scene} scene
|
||||
* @default null
|
||||
*/
|
||||
scene: null,
|
||||
|
||||
/**
|
||||
* !#en Indicates the raw assets of this scene can be load after scene launched.
|
||||
* !#zh 指示该场景依赖的资源可否在场景切换后再延迟加载。
|
||||
* @property {Boolean} asyncLoadAssets
|
||||
* @default undefined
|
||||
* @default false
|
||||
*/
|
||||
asyncLoadAssets: undefined
|
||||
asyncLoadAssets: undefined,
|
||||
|
||||
//// backup prefab assets in editor
|
||||
//// {string} assetUuid: {cc.Node} rootInPrefab
|
||||
//_prefabDatas: {
|
||||
// default: null,
|
||||
// editorOnly: true
|
||||
//}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ var SpriteAtlas = cc.Class({
|
||||
* Returns the sprite frame correspond to the given key in sprite atlas.
|
||||
* @method getSpriteFrame
|
||||
* @param {String} key
|
||||
* @returns {cc.SpriteFrame}
|
||||
* @returns {SpriteFrame}
|
||||
*/
|
||||
getSpriteFrame: function (key) {
|
||||
return this._spriteFrames[key];
|
||||
@@ -68,7 +68,7 @@ var SpriteAtlas = cc.Class({
|
||||
/**
|
||||
* Returns the sprite frames in sprite atlas.
|
||||
* @method getSpriteFrames
|
||||
* @returns {[cc.SpriteFrame]}
|
||||
* @returns {[SpriteFrame]}
|
||||
*/
|
||||
getSpriteFrames: function () {
|
||||
var frames = [];
|
||||
|
||||
@@ -286,7 +286,7 @@ cc.js.addon(_p, EventTarget.prototype);
|
||||
/**
|
||||
* Creates a cc.AtlasNode with an Atlas file the width and height of each item and the quantity of items to render
|
||||
* @deprecated since v3.0, please use new construction instead
|
||||
* @function
|
||||
* @method create
|
||||
* @static
|
||||
* @param {String} tile
|
||||
* @param {Number} tileWidth
|
||||
|
||||
@@ -208,10 +208,10 @@ _ccsg.Node.RenderCmd.prototype = {
|
||||
skx = 99999999;
|
||||
if (sky === Infinity)
|
||||
sky = 99999999;
|
||||
t.a = a + b * sky;
|
||||
t.b = b + a * sky;
|
||||
t.c = c + d * skx;
|
||||
t.d = d + c * skx;
|
||||
t.a = a + c * sky;
|
||||
t.b = b + d * sky;
|
||||
t.c = c + a * skx;
|
||||
t.d = d + b * skx;
|
||||
}
|
||||
|
||||
if (appX || appY) {
|
||||
@@ -449,21 +449,21 @@ _ccsg.Node.RenderCmd.prototype = {
|
||||
var colorDirty = locFlag & dirtyFlags.colorDirty,
|
||||
opacityDirty = locFlag & dirtyFlags.opacityDirty;
|
||||
|
||||
if(locFlag & dirtyFlags.contentDirty) {
|
||||
if (locFlag & dirtyFlags.contentDirty) {
|
||||
this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty);
|
||||
this._dirtyFlag &= ~dirtyFlags.contentDirty;
|
||||
}
|
||||
|
||||
if(colorDirty)
|
||||
if (colorDirty)
|
||||
this._updateDisplayColor();
|
||||
|
||||
if(opacityDirty)
|
||||
if (opacityDirty)
|
||||
this._updateDisplayOpacity();
|
||||
|
||||
if(colorDirty || opacityDirty)
|
||||
if (colorDirty || opacityDirty)
|
||||
this._updateColor();
|
||||
|
||||
if(locFlag & dirtyFlags.transformDirty){
|
||||
if (locFlag & dirtyFlags.transformDirty) {
|
||||
//update the transform
|
||||
this.transform(this.getParentRenderCmd(), true);
|
||||
this._dirtyFlag &= ~dirtyFlags.transformDirty;
|
||||
@@ -487,7 +487,7 @@ _ccsg.Node.RenderCmd.prototype = {
|
||||
//update the opacity
|
||||
this._syncDisplayOpacity();
|
||||
|
||||
if(colorDirty || opacityDirty)
|
||||
if (colorDirty || opacityDirty)
|
||||
this._updateColor();
|
||||
|
||||
if (transformDirty)
|
||||
|
||||
@@ -91,8 +91,9 @@ function alignToParent (node, widget) {
|
||||
else {
|
||||
width = node.width * scaleX;
|
||||
if (widget.isAlignHorizontalCenter) {
|
||||
var parentCenter = (0.5 - parentAnchor.x) * parentWidth; // no offset
|
||||
x = parentCenter + (anchorX - 0.5) * width;
|
||||
var localHorizontalCenter = widget._isAbsHorizontalCenter ? widget._horizontalCenter : widget._horizontalCenter * parentWidth;
|
||||
var parentCenter = (0.5 - parentAnchor.x) * parentWidth;
|
||||
x = parentCenter + (anchorX - 0.5) * width + localHorizontalCenter;
|
||||
}
|
||||
else if (widget.isAlignLeft) {
|
||||
x = localLeft + anchorX * width;
|
||||
@@ -137,8 +138,9 @@ function alignToParent (node, widget) {
|
||||
else {
|
||||
height = node.height * scaleY;
|
||||
if (widget.isAlignVerticalCenter) {
|
||||
var parentMiddle = (0.5 - parentAnchor.y) * parentHeight; // no offset
|
||||
y = parentMiddle + (anchorY - 0.5) * height;
|
||||
var localVerticalCenter = widget._isAbsVerticalCenter ? widget._verticalCenter : widget._verticalCenter * parentHeight;
|
||||
var parentMiddle = (0.5 - parentAnchor.y) * parentHeight;
|
||||
y = parentMiddle + (anchorY - 0.5) * height + localVerticalCenter;
|
||||
}
|
||||
else if (widget.isAlignBottom) {
|
||||
y = localBottom + anchorY * height;
|
||||
@@ -156,7 +158,7 @@ function visitNode (node) {
|
||||
var widget = node._widget;
|
||||
if (widget) {
|
||||
alignToParent(node, widget);
|
||||
if ((!CC_EDITOR || _Scene.AnimUtils.curAnimState) && widget.isAlignOnce) {
|
||||
if ((!CC_EDITOR || animationState.animatedSinceLastFrame) && widget.isAlignOnce) {
|
||||
widget.enabled = false;
|
||||
}
|
||||
else {
|
||||
@@ -172,7 +174,34 @@ function visitNode (node) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CC_EDITOR) {
|
||||
var animationState = {
|
||||
previewing: false,
|
||||
time: 0,
|
||||
animatedSinceLastFrame: false,
|
||||
};
|
||||
}
|
||||
|
||||
function refreshScene () {
|
||||
// check animation editor
|
||||
if (CC_EDITOR && window._Scene && _Scene.AnimUtils) {
|
||||
var nowPreviewing = !!_Scene.AnimUtils.curAnimState;
|
||||
if (nowPreviewing !== animationState.previewing) {
|
||||
animationState.previewing = nowPreviewing;
|
||||
if (nowPreviewing) {
|
||||
animationState.animatedSinceLastFrame = true;
|
||||
animationState.time = _Scene.AnimUtils.curAnimState.time;
|
||||
}
|
||||
else {
|
||||
animationState.animatedSinceLastFrame = false;
|
||||
}
|
||||
}
|
||||
else if (nowPreviewing && animationState.time !== _Scene.AnimUtils.curAnimState.time) {
|
||||
animationState.animatedSinceLastFrame = true;
|
||||
animationState.time = _Scene.AnimUtils.curAnimState.time;
|
||||
}
|
||||
}
|
||||
|
||||
var scene = cc.director.getScene();
|
||||
if (scene) {
|
||||
widgetManager.isAligning = true;
|
||||
@@ -180,14 +209,15 @@ function refreshScene () {
|
||||
widgetManager._nodesWithWidget.length = 0;
|
||||
visitNode(scene);
|
||||
widgetManager._nodesOrderDirty = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
var i, node, nodes = widgetManager._nodesWithWidget, len = nodes.length;
|
||||
if (CC_EDITOR && _Scene.AnimUtils.curAnimState) {
|
||||
// always check isAlignOnce because animation mode maybe changed
|
||||
if (CC_EDITOR && window._Scene && _Scene.AnimUtils && _Scene.AnimUtils.curAnimState) {
|
||||
var editingNode = _Scene.AnimUtils.curRootNode;
|
||||
for (i = len - 1; i >= 0; i--) {
|
||||
node = nodes[i];
|
||||
var widget = node._widget;
|
||||
if (widget.isAlignOnce) {
|
||||
if (widget.isAlignOnce && animationState.animatedSinceLastFrame && node.isChildOf(editingNode)) {
|
||||
// widget contains in _nodesWithWidget should aligned at least once
|
||||
widget.enabled = false;
|
||||
}
|
||||
@@ -206,6 +236,10 @@ function refreshScene () {
|
||||
widgetManager.isAligning = false;
|
||||
}
|
||||
|
||||
// check animation editor
|
||||
if (CC_EDITOR) {
|
||||
animationState.animatedSinceLastFrame = false;
|
||||
}
|
||||
}
|
||||
|
||||
var adjustWidgetToAllowMovingInEditor = CC_EDITOR && function (event) {
|
||||
@@ -237,14 +271,10 @@ var adjustWidgetToAllowMovingInEditor = CC_EDITOR && function (event) {
|
||||
this.right -= (this.isAbsoluteRight ? delta.x : deltaInPercent.x);
|
||||
}
|
||||
if (this.isAlignHorizontalCenter) {
|
||||
if (oldPos.x !== newPos.x) {
|
||||
this.isAlignHorizontalCenter = false;
|
||||
}
|
||||
this.horizontalCenter += (this.isAbsoluteHorizontalCenter ? delta.x : deltaInPercent.x);
|
||||
}
|
||||
if (this.isAlignVerticalCenter) {
|
||||
if (oldPos.y !== newPos.y) {
|
||||
this.isAlignVerticalCenter = false;
|
||||
}
|
||||
this.verticalCenter += (this.isAbsoluteVerticalCenter ? delta.y : deltaInPercent.y);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -280,14 +310,10 @@ var adjustWidgetToAllowResizingInEditor = CC_EDITOR && function (event) {
|
||||
this.right -= (this.isAbsoluteRight ? delta.x : deltaInPercent.x) * (1 - anchor.x);
|
||||
}
|
||||
if (this.isAlignHorizontalCenter) {
|
||||
if (delta.x !== 0 && anchor.x !== 0.5) {
|
||||
this.isAlignHorizontalCenter = false;
|
||||
}
|
||||
this.horizontalCenter -= (this.isAbsoluteHorizontalCenter ? delta.x : deltaInPercent.x);
|
||||
}
|
||||
if (this.isAlignVerticalCenter) {
|
||||
if (delta.y !== 0 && anchor.y !== 0.5) {
|
||||
this.isAlignVerticalCenter = false;
|
||||
}
|
||||
this.verticalCenter -= (this.isAbsoluteVerticalCenter ? delta.y : deltaInPercent.y);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ cc.js.getset(CollisionManager.prototype, 'enabledDebugDraw',
|
||||
}
|
||||
else if (!value && this._enabledDebugDraw) {
|
||||
this._debugDrawer.clear();
|
||||
cc.director.getScene()._sgNode.removeChild(this._debugDrawer);
|
||||
this._debugDrawer.removeFromParent(false);
|
||||
cc.director.off(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneLaunched, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,17 +166,16 @@ var Animation = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
__preload: function () {
|
||||
if (CC_EDITOR || !this.enabled) return;
|
||||
onEnable: function () {
|
||||
if (!CC_EDITOR && this.playOnLoad && this._defaultClip) {
|
||||
this.playOnLoad = false;
|
||||
|
||||
if (this.playOnLoad && this._defaultClip) {
|
||||
var state = this.getAnimationState(this._defaultClip.name);
|
||||
this._animator.playState(state);
|
||||
}
|
||||
},
|
||||
|
||||
onEnable: function () {
|
||||
this.resume();
|
||||
else {
|
||||
this.resume();
|
||||
}
|
||||
},
|
||||
|
||||
onDisable: function () {
|
||||
|
||||
@@ -448,7 +448,7 @@ var Button = cc.Class({
|
||||
},
|
||||
|
||||
_onMouseMoveIn: function () {
|
||||
if (this._pressed || !this.interactable || !this.enabledInHierarchy) return;
|
||||
if (!this.hoverSprite || this._pressed || !this.interactable || !this.enabledInHierarchy) return;
|
||||
|
||||
if (!this._hovered) {
|
||||
this._hovered = true;
|
||||
|
||||
@@ -80,7 +80,7 @@ cc.Component.EventHandler = cc.Class({
|
||||
/**
|
||||
* @method emitEvents
|
||||
* @param {Component.EventHandler[]} events
|
||||
* @param {Any} ...params
|
||||
* @param {any} ...params
|
||||
* @statics
|
||||
*/
|
||||
emitEvents: function(events) {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Base = cc._RendererInSG;
|
||||
|
||||
/**
|
||||
* @class Mask
|
||||
* @extends _RendererInSG
|
||||
@@ -51,7 +53,7 @@ var MaskType = cc.Enum({
|
||||
|
||||
var Mask = cc.Class({
|
||||
name: 'cc.Mask',
|
||||
extends: cc._RendererInSG,
|
||||
extends: Base,
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
menu: 'i18n:MAIN_MENU.component.renderers/Mask',
|
||||
@@ -167,12 +169,6 @@ var Mask = cc.Class({
|
||||
this.node.off('anchor-changed', this._refreshStencil, this);
|
||||
},
|
||||
|
||||
onDestroy: CC_JSB && function () {
|
||||
this._super();
|
||||
this._clippingStencil.release();
|
||||
this._clippingStencil = null;
|
||||
},
|
||||
|
||||
_calculateCircle: function(center, radius, segements) {
|
||||
var polies =[];
|
||||
var anglePerStep = Math.PI * 2 / segements;
|
||||
@@ -208,4 +204,14 @@ var Mask = cc.Class({
|
||||
}
|
||||
});
|
||||
|
||||
if (CC_JSB) {
|
||||
// override onDestroy
|
||||
Mask.prototype.__superOnDestroy = Base.prototype.onDestroy;
|
||||
Mask.prototype.onDestroy = function () {
|
||||
this.__superOnDestroy();
|
||||
this._clippingStencil.release();
|
||||
this._clippingStencil = null;
|
||||
};
|
||||
}
|
||||
|
||||
cc.Mask = module.exports = Mask;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
*/
|
||||
var RendererInSG = cc.Class({
|
||||
extends: require('./CCSGComponent'),
|
||||
name: 'cc._RendererInSG',
|
||||
|
||||
ctor: function () {
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
*/
|
||||
var RendererUnderSG = cc.Class({
|
||||
extends: require('./CCSGComponent'),
|
||||
name: 'cc._RendererUnderSG',
|
||||
|
||||
ctor: function () {
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,7 @@ var SceneGraphHelper = require('../utils/scene-graph-helper');
|
||||
*/
|
||||
var SGComponent = cc.Class({
|
||||
extends: require('./CCComponent'),
|
||||
name: 'cc._SGComponent',
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
executeInEditMode: true,
|
||||
|
||||
@@ -160,7 +160,7 @@ var ScrollView = cc.Class({
|
||||
* @property {Node} content
|
||||
*/
|
||||
content: {
|
||||
default: null,
|
||||
default: undefined,
|
||||
type: cc.Node,
|
||||
tooltip: 'i18n:COMPONENT.scrollview.content',
|
||||
},
|
||||
@@ -240,7 +240,7 @@ var ScrollView = cc.Class({
|
||||
* @property {Scrollbar} horizontalScrollBar
|
||||
*/
|
||||
horizontalScrollBar: {
|
||||
default: null,
|
||||
default: undefined,
|
||||
type: cc.Scrollbar,
|
||||
tooltip: 'i18n:COMPONENT.scrollview.horizontal_bar',
|
||||
notify: function() {
|
||||
@@ -258,7 +258,7 @@ var ScrollView = cc.Class({
|
||||
* @property {Scrollbar} verticalScrollBar
|
||||
*/
|
||||
verticalScrollBar: {
|
||||
default: null,
|
||||
default: undefined,
|
||||
type: cc.Scrollbar,
|
||||
tooltip: 'i18n:COMPONENT.scrollview.vertical_bar',
|
||||
notify: function() {
|
||||
@@ -278,6 +278,18 @@ var ScrollView = cc.Class({
|
||||
scrollEvents: {
|
||||
default: [],
|
||||
type: cc.Component.EventHandler
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en If cancelInnerEvents is set to true, the scroll behavior will cancel touch events on inner content nodes of the scroll view
|
||||
* It's set to true by default.
|
||||
* !#zh 如果这个属性被设置为 true,那么滚动行为会取消 ScrollView 的子节点上注册的触摸事件,默认被设置为 true。
|
||||
* 注意,子节点上的 touchstart 事件仍然会触发,触点移动距离非常短的情况下 touchmove 和 touchend 也不会受影响。
|
||||
* @property {Boolean} cancelInnerEvents
|
||||
*/
|
||||
cancelInnerEvents: {
|
||||
default: true,
|
||||
animatable: false,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -801,6 +813,7 @@ var ScrollView = cc.Class({
|
||||
}
|
||||
|
||||
this._moveContent(moveDelta);
|
||||
this._adjustContentOutOfBoundary();
|
||||
},
|
||||
|
||||
_calculateBoundary: function() {
|
||||
@@ -846,17 +859,22 @@ var ScrollView = cc.Class({
|
||||
if (this.content) {
|
||||
this._handleMoveLogic(touch);
|
||||
}
|
||||
// Do not prevent touch events in inner nodes
|
||||
if (!this.cancelInnerEvents) {
|
||||
return;
|
||||
}
|
||||
|
||||
var deltaMove = cc.pSub(touch.getLocation(), touch.getStartLocation());
|
||||
//FIXME: touch move delta should be calculated by DPI.
|
||||
if (cc.pLength(deltaMove) > 7) {
|
||||
this._touchMoved = true;
|
||||
if (event.target !== this.node) {
|
||||
if (!this._touchMoved && event.target !== this.node) {
|
||||
// Simulate touch cancel for target node
|
||||
var cancelEvent = new cc.Event.EventTouch(event.getTouches(), event.bubbles);
|
||||
cancelEvent.type = cc.Node.EventType.TOUCH_CANCEL;
|
||||
cancelEvent.touch = event.touch;
|
||||
cancelEvent.simulate = true;
|
||||
event.target.dispatchEvent(cancelEvent);
|
||||
this._touchMoved = true;
|
||||
}
|
||||
event.stopPropagation();
|
||||
}
|
||||
@@ -1307,8 +1325,25 @@ var ScrollView = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
_adjustContentOutOfBoundary: function () {
|
||||
this._outOfBoundaryAmountDirty = true;
|
||||
if(this._isOutOfBoundary()) {
|
||||
var outOfBoundary = this._getHowMuchOutOfBoundary(cc.p(0, 0));
|
||||
var newPosition = cc.pAdd(this.getContentPosition(), outOfBoundary);
|
||||
if(this.content) {
|
||||
this.content.setPosition(newPosition);
|
||||
this._updateScrollBar(0);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
start: function() {
|
||||
this._calculateBoundary();
|
||||
//Because widget component will adjust content position and scrollview position is correct after visit
|
||||
//So this event could make sure the content is on the correct position after loading.
|
||||
if(this.content) {
|
||||
cc.director.once(cc.Director.EVENT_AFTER_VISIT, this._adjustContentOutOfBoundary, this);
|
||||
}
|
||||
},
|
||||
|
||||
onDestroy: function() {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Base = require('./CCRendererUnderSG');
|
||||
|
||||
/**
|
||||
* !#en Enum for sprite type.
|
||||
* !#zh Sprite 类型
|
||||
@@ -113,7 +115,7 @@ var SizeMode = cc.Enum({
|
||||
*/
|
||||
var Sprite = cc.Class({
|
||||
name: 'cc.Sprite',
|
||||
extends: require('./CCRendererUnderSG'),
|
||||
extends: Base,
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
menu: 'i18n:MAIN_MENU.component.renderers/Sprite',
|
||||
@@ -379,15 +381,6 @@ var Sprite = cc.Class({
|
||||
SizeMode: SizeMode,
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Sets whether the sprite is visible or not.
|
||||
* !#zh 设置精灵是否可见
|
||||
* @method setVisible
|
||||
* @param {Boolean} visible
|
||||
* @override
|
||||
* @example
|
||||
* sprite.setVisible(false);
|
||||
*/
|
||||
setVisible: function (visible) {
|
||||
this.enabled = visible;
|
||||
},
|
||||
@@ -492,11 +485,6 @@ var Sprite = cc.Class({
|
||||
return this._sgNode.getInsetBottom();
|
||||
},
|
||||
|
||||
__preload: CC_EDITOR && function () {
|
||||
this._super();
|
||||
this.node.on('size-changed', this._resized, this);
|
||||
},
|
||||
|
||||
onEnable: function () {
|
||||
if (this._sgNode) {
|
||||
if (this._spriteFrame && this._spriteFrame.textureLoaded()) {
|
||||
@@ -505,11 +493,6 @@ var Sprite = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
onDestroy: CC_EDITOR && function () {
|
||||
this._super();
|
||||
this.node.off('size-changed', this._resized, this);
|
||||
},
|
||||
|
||||
_applyAtlas: CC_EDITOR && function (spriteFrame) {
|
||||
// Set atlas
|
||||
if (spriteFrame && spriteFrame._atlasUuid) {
|
||||
@@ -632,6 +615,21 @@ var Sprite = cc.Class({
|
||||
},
|
||||
});
|
||||
|
||||
if (CC_EDITOR) {
|
||||
// override __preload
|
||||
Sprite.prototype.__superPreload = Base.prototype.__preload;
|
||||
Sprite.prototype.__preload = function () {
|
||||
this.__superPreload();
|
||||
this.node.on('size-changed', this._resized, this);
|
||||
};
|
||||
// override onDestroy
|
||||
Sprite.prototype.__superOnDestroy = Base.prototype.onDestroy;
|
||||
Sprite.prototype.onDestroy = function () {
|
||||
this.__superOnDestroy();
|
||||
this.node.off('size-changed', this._resized, this);
|
||||
};
|
||||
}
|
||||
|
||||
var misc = require('../utils/misc');
|
||||
var SameNameGetSets = ['atlas', 'capInsets', 'insetLeft', 'insetTop', 'insetRight', 'insetBottom'];
|
||||
var DiffNameGetSets = {
|
||||
|
||||
@@ -147,21 +147,24 @@ var VideoPlayer = cc.Class({
|
||||
url: cc.RawAsset
|
||||
},
|
||||
|
||||
_time: 0,
|
||||
/**
|
||||
* !#en The current time when video start to play.
|
||||
* !#zh 从当前时间点开始播放视频
|
||||
* @property {Float} currentTime
|
||||
* !#en The current playback time of the now playing item in seconds, you could also change the start playback time.
|
||||
* !#zh 指定视频从什么时间点开始播放,单位是秒,也可以用来获取当前视频播放的时间进度。
|
||||
* @property {Number} currentTime
|
||||
*/
|
||||
currentTime: {
|
||||
tooltip: 'i18n:COMPONENT.videoplayer.currentTime',
|
||||
type: cc.Float,
|
||||
set: function ( time ) {
|
||||
this._time = time;
|
||||
this._sgNode.seekTo(time);
|
||||
if(this._sgNode) {
|
||||
this._sgNode.seekTo(time);
|
||||
}
|
||||
},
|
||||
get: function () {
|
||||
return this._time;
|
||||
if(this._sgNode) {
|
||||
return this._sgNode.currentTime();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -210,7 +213,6 @@ var VideoPlayer = cc.Class({
|
||||
},
|
||||
|
||||
onLoad: function() {
|
||||
|
||||
if(CC_JSB) {
|
||||
if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) {
|
||||
this.enabled = false;
|
||||
@@ -318,6 +320,28 @@ var VideoPlayer = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Gets the duration of the video
|
||||
* !#zh 获取视频文件的播放总时长
|
||||
*/
|
||||
getDuration: function() {
|
||||
if(this._sgNode) {
|
||||
return this._sgNode.duration();
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Determine whether video is playing or not.
|
||||
* !#zh 判断当前视频是否处于播放状态
|
||||
*/
|
||||
isPlaying: function() {
|
||||
if(this._sgNode) {
|
||||
return this._sgNode.isPlaying();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
cc.VideoPlayer = module.exports = VideoPlayer;
|
||||
|
||||
@@ -38,8 +38,10 @@ var LEFT_RIGHT = LEFT | RIGHT;
|
||||
* !#en
|
||||
* Stores and manipulate the anchoring based on its parent.
|
||||
* Widget are used for GUI but can also be used for other things.
|
||||
* Widget will adjust current node's position and size automatically, but the results after adjustment can not be obtained until the next frame.
|
||||
* !#zh
|
||||
* Widget 组件,用于设置和适配其相对于父节点的边距,Widget 通常被用于 UI 界面,也可以用于其他地方。
|
||||
* Widget 会自动调整当前节点的坐标和宽高,不过目前调整后的结果要到下一帧才能在脚本里获取到。
|
||||
* @class Widget
|
||||
* @extends Component
|
||||
*/
|
||||
@@ -301,8 +303,80 @@ var Widget = cc.Class({
|
||||
tooltip: 'i18n:COMPONENT.widget.right',
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Horizontal aligns the midpoint offset value,
|
||||
* the value can be negative, Only available in 'isAlignHorizontalCenter' open.
|
||||
* !#zh 水平居中的偏移值,可填写负值,只有在 isAlignHorizontalCenter 开启时才有作用。
|
||||
* @property horizontalCenter
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
*/
|
||||
horizontalCenter: {
|
||||
get: function () {
|
||||
return this._horizontalCenter;
|
||||
},
|
||||
set: function (value) {
|
||||
this._horizontalCenter = value;
|
||||
},
|
||||
tooltip: 'i18n:COMPONENT.widget.horizontal_center',
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Vertical aligns the midpoint offset value,
|
||||
* the value can be negative, Only available in 'isAlignVerticalCenter' open.
|
||||
* !#zh 垂直居中的偏移值,可填写负值,只有在 isAlignVerticalCenter 开启时才有作用。
|
||||
* @property verticalCenter
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
*/
|
||||
verticalCenter: {
|
||||
get: function () {
|
||||
return this._verticalCenter;
|
||||
},
|
||||
set: function (value) {
|
||||
this._verticalCenter = value;
|
||||
},
|
||||
tooltip: 'i18n:COMPONENT.widget.vertical_center',
|
||||
},
|
||||
|
||||
// PARCENTAGE OR ABSOLUTE
|
||||
|
||||
/**
|
||||
* !#en If true, horizontalCenter is pixel margin, otherwise is percentage (0 - 1) margin.
|
||||
* !#zh 如果为 true,"horizontalCenter" 将会以像素作为偏移值,反之为百分比(0 到 1)。
|
||||
* @property isAbsoluteHorizontalCenter
|
||||
* @type {Boolean}
|
||||
* @default true
|
||||
*/
|
||||
isAbsoluteHorizontalCenter: {
|
||||
get: function () {
|
||||
return this._isAbsHorizontalCenter;
|
||||
},
|
||||
set: function (value) {
|
||||
this._isAbsHorizontalCenter = value;
|
||||
},
|
||||
animatable: false
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en If true, verticalCenter is pixel margin, otherwise is percentage (0 - 1) margin.
|
||||
* !#zh 如果为 true,"verticalCenter" 将会以像素作为偏移值,反之为百分比(0 到 1)。
|
||||
* @property isAbsoluteVerticalCenter
|
||||
* @type {Boolean}
|
||||
* @default true
|
||||
*/
|
||||
isAbsoluteVerticalCenter: {
|
||||
get: function () {
|
||||
return this._isAbsVerticalCenter;
|
||||
},
|
||||
set: function (value) {
|
||||
this._isAbsVerticalCenter = value;
|
||||
},
|
||||
animatable: false
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* If true, top is pixel margin, otherwise is percentage (0 - 1) margin relative to the parent's height.
|
||||
@@ -411,10 +485,14 @@ var Widget = cc.Class({
|
||||
_right: 0,
|
||||
_top: 0,
|
||||
_bottom: 0,
|
||||
_verticalCenter: 0,
|
||||
_horizontalCenter: 0,
|
||||
_isAbsLeft: true,
|
||||
_isAbsRight: true,
|
||||
_isAbsTop: true,
|
||||
_isAbsBottom: true,
|
||||
_isAbsHorizontalCenter: true,
|
||||
_isAbsVerticalCenter: true,
|
||||
|
||||
// original size before align
|
||||
_originalWidth: 0,
|
||||
|
||||
@@ -581,10 +581,18 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
|
||||
tmpEdTxt.addEventListener('input', function () {
|
||||
var editBox = thisPointer._editBox;
|
||||
|
||||
|
||||
if (this.value.length > this.maxLength) {
|
||||
this.value = this.value.slice(0, this.maxLength);
|
||||
}
|
||||
|
||||
if (editBox._delegate && editBox._delegate.editBoxTextChanged) {
|
||||
editBox._text = this.value;
|
||||
thisPointer._updateEditBoxContentStyle();
|
||||
editBox._delegate.editBoxTextChanged(editBox, editBox._text);
|
||||
if (editBox._text.toLowerCase() !== this.value.toLowerCase()) {
|
||||
editBox._text = this.value;
|
||||
thisPointer._updateEditBoxContentStyle();
|
||||
editBox._delegate.editBoxTextChanged(editBox, editBox._text);
|
||||
}
|
||||
}
|
||||
});
|
||||
tmpEdTxt.addEventListener('keypress', function (e) {
|
||||
@@ -597,6 +605,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
this.style.fontSize = editBox._placeholderFontSize + 'px';
|
||||
this.style.color = cc.colorToHex(editBox._placeholderColor);
|
||||
}
|
||||
|
||||
editBox._text = this.value;
|
||||
thisPointer._updateEditBoxContentStyle();
|
||||
thisPointer.hidden();
|
||||
@@ -670,11 +679,17 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
tmpEdTxt.style.className = "cocosEditBox";
|
||||
|
||||
tmpEdTxt.addEventListener('input', function () {
|
||||
if (this.value.length > this.maxLength) {
|
||||
this.value = this.value.slice(0, this.maxLength);
|
||||
}
|
||||
|
||||
var editBox = thisPointer._editBox;
|
||||
if (editBox._delegate && editBox._delegate.editBoxTextChanged) {
|
||||
editBox._text = this.value;
|
||||
thisPointer._updateEditBoxContentStyle();
|
||||
editBox._delegate.editBoxTextChanged(editBox, editBox._text);
|
||||
if(editBox._text.toLowerCase() !== this.value.toLowerCase()) {
|
||||
editBox._text = this.value;
|
||||
thisPointer._updateEditBoxContentStyle();
|
||||
editBox._delegate.editBoxTextChanged(editBox, editBox._text);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
* @param {Number} type
|
||||
* @param {Number} listenerID
|
||||
* @param {Number} callback
|
||||
* @return {EventListner}
|
||||
* @return {EventListener}
|
||||
*/
|
||||
cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
|
||||
_onEvent: null, // Event callback function
|
||||
|
||||
@@ -163,6 +163,7 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
|
||||
this._id = id;
|
||||
if(!this._startPointCaptured){
|
||||
this._startPoint = cc.p(this._point);
|
||||
cc.view._convertPointWithScale(this._startPoint);
|
||||
this._startPointCaptured = true;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -332,7 +332,7 @@ JS.mixin(EventTarget.prototype, {
|
||||
|
||||
// Event.AT_TARGET
|
||||
event.eventPhase = 2;
|
||||
event.currentTarget = this;
|
||||
event.target = event.currentTarget = this;
|
||||
if (caplisteners) {
|
||||
this._capturingListeners.invoke(event);
|
||||
}
|
||||
|
||||
@@ -27,16 +27,7 @@ var Js = cc.js;
|
||||
var LineCap = require('./types').LineCap;
|
||||
var LineJoin = require('./types').LineJoin;
|
||||
|
||||
var PI = 3.14159265358979323846264338327;
|
||||
|
||||
var min = Math.min;
|
||||
var max = Math.max;
|
||||
var cos = Math.cos;
|
||||
var sin = Math.sin;
|
||||
var abs = Math.abs;
|
||||
var sign = Math.sign;
|
||||
|
||||
var KAPPA90 = 0.5522847493;
|
||||
var Helper = require('./helper');
|
||||
|
||||
var CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
@@ -95,12 +86,12 @@ _p.rendering = function (ctx, scaleX, scaleY) {
|
||||
// draw api
|
||||
Js.mixin(_p, {
|
||||
setStrokeColor: function (v) {
|
||||
var fillStyle = "rgba(" + (0 | v.r) + "," + (0 | v.g) + "," + (0 | v.b) + "," + v.a / 255 + ")";
|
||||
var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['strokeStyle', fillStyle]);
|
||||
},
|
||||
|
||||
setFillColor: function (v) {
|
||||
var fillStyle = "rgba(" + (0 | v.r) + "," + (0 | v.g) + "," + (0 | v.b) + "," + v.a / 255 + ")";
|
||||
var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['fillStyle', fillStyle]);
|
||||
},
|
||||
|
||||
@@ -158,69 +149,16 @@ Js.mixin(_p, {
|
||||
},
|
||||
|
||||
//
|
||||
arc: function (cx, cy, r, a0, a1, counterclockwise) {
|
||||
// this.cmds.push(['arc', arguments]);
|
||||
var a = 0, da = 0, hda = 0, kappa = 0;
|
||||
var dx = 0, dy = 0, x = 0, y = 0, tanx = 0, tany = 0;
|
||||
var px = 0, py = 0, ptanx = 0, ptany = 0;
|
||||
var i, ndivs;
|
||||
|
||||
// Clamp angles
|
||||
da = a1 - a0;
|
||||
if (!counterclockwise) {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = PI * 2;
|
||||
} else {
|
||||
while (da < 0) da += PI * 2;
|
||||
}
|
||||
} else {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = -PI * 2;
|
||||
} else {
|
||||
while (da > 0) da -= PI * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Split arc into max 90 degree segments.
|
||||
ndivs = max(1, min(abs(da) / (PI * 0.5) + 0.5, 5)) | 0;
|
||||
hda = da / ndivs / 2.0;
|
||||
kappa = abs(4.0 / 3.0 * (1 - cos(hda)) / sin(hda));
|
||||
|
||||
if (counterclockwise) kappa = -kappa;
|
||||
|
||||
for (i = 0; i <= ndivs; i++) {
|
||||
a = a0 + da * (i / ndivs);
|
||||
dx = cos(a);
|
||||
dy = sin(a);
|
||||
x = cx + dx * r;
|
||||
y = cy + dy * r;
|
||||
tanx = -dy * r * kappa;
|
||||
tany = dx * r * kappa;
|
||||
|
||||
if (i === 0) {
|
||||
this.moveTo(x, y);
|
||||
} else {
|
||||
this.bezierCurveTo(px + ptanx, py + ptany, x - tanx, y - tany, x, y);
|
||||
}
|
||||
px = x;
|
||||
py = y;
|
||||
ptanx = tanx;
|
||||
ptany = tany;
|
||||
}
|
||||
arc: function (cx, cy, r, startAngle, endAngle, counterclockwise) {
|
||||
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
},
|
||||
|
||||
ellipse: function (cx, cy, rx, ry) {
|
||||
this.moveTo(cx - rx, cy);
|
||||
this.bezierCurveTo(cx - rx, cy + ry * KAPPA90, cx - rx * KAPPA90, cy + ry, cx, cy + ry);
|
||||
this.bezierCurveTo(cx + rx * KAPPA90, cy + ry, cx + rx, cy + ry * KAPPA90, cx + rx, cy);
|
||||
this.bezierCurveTo(cx + rx, cy - ry * KAPPA90, cx + rx * KAPPA90, cy - ry, cx, cy - ry);
|
||||
this.bezierCurveTo(cx - rx * KAPPA90, cy - ry, cx - rx, cy - ry * KAPPA90, cx - rx, cy);
|
||||
this.close();
|
||||
Helper.ellipse(this, cx, cy, rx, ry);
|
||||
},
|
||||
|
||||
circle: function (cx, cy, r) {
|
||||
this.ellipse(cx, cy, r, r);
|
||||
this.close();
|
||||
Helper.ellipse(this, cx, cy, r, r);
|
||||
},
|
||||
|
||||
rect: function (x, y, w, h) {
|
||||
@@ -232,24 +170,7 @@ Js.mixin(_p, {
|
||||
},
|
||||
|
||||
roundRect: function (x, y, w, h, r) {
|
||||
if (r < 0.1) {
|
||||
this.rect(x, y, w, h);
|
||||
return;
|
||||
} else {
|
||||
var rx = min(r, abs(w) * 0.5) * sign(w),
|
||||
ry = min(r, abs(h) * 0.5) * sign(h);
|
||||
|
||||
this.moveTo(x, y + ry);
|
||||
this.lineTo(x, y + h - ry);
|
||||
this.bezierCurveTo(x, y + h - ry * (1 - KAPPA90), x + rx * (1 - KAPPA90), y + h, x + rx, y + h);
|
||||
this.lineTo(x + w - rx, y + h);
|
||||
this.bezierCurveTo(x + w - rx * (1 - KAPPA90), y + h, x + w, y + h - ry * (1 - KAPPA90), x + w, y + h - ry);
|
||||
this.lineTo(x + w, y + ry);
|
||||
this.bezierCurveTo(x + w, y + ry * (1 - KAPPA90), x + w - rx * (1 - KAPPA90), y, x + w - rx, y);
|
||||
this.lineTo(x + rx, y);
|
||||
this.bezierCurveTo(x + rx * (1 - KAPPA90), y, x, y + ry * (1 - KAPPA90), x, y + ry);
|
||||
this.close();
|
||||
}
|
||||
Helper.roundRect(this, x, y, w, h, r);
|
||||
},
|
||||
|
||||
fillRect: function (x, y, w, h) {
|
||||
|
||||
@@ -30,18 +30,18 @@ var LineJoin = require('./types').LineJoin;
|
||||
|
||||
var Earcut = require('./earcut');
|
||||
|
||||
var Helper = require('./Helper');
|
||||
|
||||
var Vec2 = cc.Vec2;
|
||||
var Js = cc.js;
|
||||
|
||||
// Math
|
||||
var PI = 3.14159265358979323846264338327;
|
||||
var PI_2 = PI*2;
|
||||
var INIT_VERTS_SIZE = 32;
|
||||
var KAPPA90 = 0.5522847493;
|
||||
|
||||
var VERTS_FLOAT_LENGTH = 2;
|
||||
var VERTS_BYTE_LENGTH = 8;
|
||||
|
||||
var PI = Math.PI;
|
||||
var min = Math.min;
|
||||
var max = Math.max;
|
||||
var ceil = Math.ceil;
|
||||
@@ -50,7 +50,6 @@ var cos = Math.cos;
|
||||
var sin = Math.sin;
|
||||
var atan2 = Math.atan2;
|
||||
var abs = Math.abs;
|
||||
var sign = Math.sign;
|
||||
|
||||
function clamp (v, min, max) {
|
||||
if (v < min) {
|
||||
@@ -206,86 +205,17 @@ Js.mixin(_p, {
|
||||
},
|
||||
|
||||
//
|
||||
arc: function (cx, cy, r, a0, a1, counterclockwise) {
|
||||
var a = 0, da = 0, hda = 0, kappa = 0;
|
||||
var dx = 0, dy = 0, x = 0, y = 0, tanx = 0, tany = 0;
|
||||
var px = 0, py = 0, ptanx = 0, ptany = 0;
|
||||
var i, ndivs;
|
||||
|
||||
// Clamp angles
|
||||
da = a1 - a0;
|
||||
if (!counterclockwise) {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = PI * 2;
|
||||
} else {
|
||||
while (da < 0) da += PI * 2;
|
||||
}
|
||||
} else {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = -PI * 2;
|
||||
} else {
|
||||
while (da > 0) da -= PI * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Split arc into max 90 degree segments.
|
||||
ndivs = max(1, min(abs(da) / (PI * 0.5) + 0.5, 5)) | 0;
|
||||
hda = da / ndivs / 2.0;
|
||||
kappa = abs(4.0 / 3.0 * (1 - cos(hda)) / sin(hda));
|
||||
|
||||
if (counterclockwise) kappa = -kappa;
|
||||
|
||||
for (i = 0; i <= ndivs; i++) {
|
||||
a = a0 + da * (i / ndivs);
|
||||
dx = cos(a);
|
||||
dy = sin(a);
|
||||
x = cx + dx * r;
|
||||
y = cy + dy * r;
|
||||
tanx = -dy * r * kappa;
|
||||
tany = dx * r * kappa;
|
||||
|
||||
if (i === 0) {
|
||||
this.moveTo(x, y);
|
||||
} else {
|
||||
this.bezierCurveTo(px + ptanx, py + ptany, x - tanx, y - tany, x, y);
|
||||
}
|
||||
px = x;
|
||||
py = y;
|
||||
ptanx = tanx;
|
||||
ptany = tany;
|
||||
}
|
||||
|
||||
// this.close();
|
||||
// this._curPath.complex = false;
|
||||
arc: function (cx, cy, r, startAngle, endAngle, counterclockwise) {
|
||||
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
},
|
||||
|
||||
ellipse: function (cx, cy, rx, ry) {
|
||||
this.moveTo(cx - rx, cy);
|
||||
this.bezierCurveTo(cx - rx, cy + ry * KAPPA90, cx - rx * KAPPA90, cy + ry, cx, cy + ry);
|
||||
this.bezierCurveTo(cx + rx * KAPPA90, cy + ry, cx + rx, cy + ry * KAPPA90, cx + rx, cy);
|
||||
this.bezierCurveTo(cx + rx, cy - ry * KAPPA90, cx + rx * KAPPA90, cy - ry, cx, cy - ry);
|
||||
this.bezierCurveTo(cx - rx * KAPPA90, cy - ry, cx - rx, cy - ry * KAPPA90, cx - rx, cy);
|
||||
|
||||
this.close();
|
||||
Helper.ellipse(this, cx, cy, rx, ry);
|
||||
this._curPath.complex = false;
|
||||
},
|
||||
|
||||
circle: function (cx, cy, r) {
|
||||
// this.ellipse(cx, cy, r, r);
|
||||
var divs = this._curveDivs(r, PI_2, this._tessTol);
|
||||
var step = PI_2 / divs;
|
||||
|
||||
this.moveTo(cx, cy + r);
|
||||
|
||||
for (var i = 1; i < divs; i++) {
|
||||
var angle = step * i;
|
||||
var x = r * sin(angle);
|
||||
var y = r * cos(angle);
|
||||
|
||||
this.lineTo(cx + x, cy + y);
|
||||
}
|
||||
|
||||
this.close();
|
||||
Helper.ellipse(this, cx, cy, r, r);
|
||||
this._curPath.complex = false;
|
||||
},
|
||||
|
||||
@@ -299,25 +229,8 @@ Js.mixin(_p, {
|
||||
},
|
||||
|
||||
roundRect: function (x, y, w, h, r) {
|
||||
if (r < 0.1) {
|
||||
this.rect(x, y, w, h);
|
||||
return;
|
||||
} else {
|
||||
var rx = min(r, abs(w) * 0.5) * sign(w),
|
||||
ry = min(r, abs(h) * 0.5) * sign(h);
|
||||
|
||||
this.moveTo(x, y + ry);
|
||||
this.lineTo(x, y + h - ry);
|
||||
this.bezierCurveTo(x, y + h - ry * (1 - KAPPA90), x + rx * (1 - KAPPA90), y + h, x + rx, y + h);
|
||||
this.lineTo(x + w - rx, y + h);
|
||||
this.bezierCurveTo(x + w - rx * (1 - KAPPA90), y + h, x + w, y + h - ry * (1 - KAPPA90), x + w, y + h - ry);
|
||||
this.lineTo(x + w, y + ry);
|
||||
this.bezierCurveTo(x + w, y + ry * (1 - KAPPA90), x + w - rx * (1 - KAPPA90), y, x + w - rx, y);
|
||||
this.lineTo(x + rx, y);
|
||||
this.bezierCurveTo(x + rx * (1 - KAPPA90), y, x, y + ry * (1 - KAPPA90), x, y + ry);
|
||||
this.close();
|
||||
this._curPath.complex = false;
|
||||
}
|
||||
Helper.roundRect(this, x, y, w, h, r);
|
||||
this._curPath.complex = false;
|
||||
},
|
||||
|
||||
fillRect: function (x, y, w, h) {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
|
||||
var PI = Math.PI;
|
||||
var min = Math.min;
|
||||
var max = Math.max;
|
||||
var cos = Math.cos;
|
||||
var sin = Math.sin;
|
||||
var abs = Math.abs;
|
||||
var sign = Math.sign;
|
||||
|
||||
var KAPPA90 = 0.5522847493;
|
||||
|
||||
function arc (ctx, cx, cy, r, startAngle, endAngle, counterclockwise) {
|
||||
counterclockwise = counterclockwise || false;
|
||||
|
||||
var a = 0, da = 0, hda = 0, kappa = 0;
|
||||
var dx = 0, dy = 0, x = 0, y = 0, tanx = 0, tany = 0;
|
||||
var px = 0, py = 0, ptanx = 0, ptany = 0;
|
||||
var i, ndivs;
|
||||
|
||||
// Clamp angles
|
||||
da = endAngle - startAngle;
|
||||
if (counterclockwise) {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = PI * 2;
|
||||
} else {
|
||||
while (da < 0) da += PI * 2;
|
||||
}
|
||||
} else {
|
||||
if (abs(da) >= PI * 2) {
|
||||
da = -PI * 2;
|
||||
} else {
|
||||
while (da > 0) da -= PI * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Split arc into max 90 degree segments.
|
||||
ndivs = max(1, min(abs(da) / (PI * 0.5) + 0.5, 5)) | 0;
|
||||
hda = da / ndivs / 2.0;
|
||||
kappa = abs(4.0 / 3.0 * (1 - cos(hda)) / sin(hda));
|
||||
|
||||
if (!counterclockwise) kappa = -kappa;
|
||||
|
||||
for (i = 0; i <= ndivs; i++) {
|
||||
a = startAngle + da * (i / ndivs);
|
||||
dx = cos(a);
|
||||
dy = sin(a);
|
||||
x = cx + dx * r;
|
||||
y = cy + dy * r;
|
||||
tanx = -dy * r * kappa;
|
||||
tany = dx * r * kappa;
|
||||
|
||||
if (i === 0) {
|
||||
ctx.moveTo(x, y);
|
||||
} else {
|
||||
ctx.bezierCurveTo(px + ptanx, py + ptany, x - tanx, y - tany, x, y);
|
||||
}
|
||||
px = x;
|
||||
py = y;
|
||||
ptanx = tanx;
|
||||
ptany = tany;
|
||||
}
|
||||
}
|
||||
|
||||
function ellipse (ctx, cx, cy, rx, ry) {
|
||||
ctx.moveTo(cx - rx, cy);
|
||||
ctx.bezierCurveTo(cx - rx, cy + ry * KAPPA90, cx - rx * KAPPA90, cy + ry, cx, cy + ry);
|
||||
ctx.bezierCurveTo(cx + rx * KAPPA90, cy + ry, cx + rx, cy + ry * KAPPA90, cx + rx, cy);
|
||||
ctx.bezierCurveTo(cx + rx, cy - ry * KAPPA90, cx + rx * KAPPA90, cy - ry, cx, cy - ry);
|
||||
ctx.bezierCurveTo(cx - rx * KAPPA90, cy - ry, cx - rx, cy - ry * KAPPA90, cx - rx, cy);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
function roundRect (ctx, x, y, w, h, r) {
|
||||
if (r < 0.1) {
|
||||
ctx.rect(x, y, w, h);
|
||||
return;
|
||||
} else {
|
||||
var rx = min(r, abs(w) * 0.5) * sign(w),
|
||||
ry = min(r, abs(h) * 0.5) * sign(h);
|
||||
|
||||
ctx.moveTo(x, y + ry);
|
||||
ctx.lineTo(x, y + h - ry);
|
||||
ctx.bezierCurveTo(x, y + h - ry * (1 - KAPPA90), x + rx * (1 - KAPPA90), y + h, x + rx, y + h);
|
||||
ctx.lineTo(x + w - rx, y + h);
|
||||
ctx.bezierCurveTo(x + w - rx * (1 - KAPPA90), y + h, x + w, y + h - ry * (1 - KAPPA90), x + w, y + h - ry);
|
||||
ctx.lineTo(x + w, y + ry);
|
||||
ctx.bezierCurveTo(x + w, y + ry * (1 - KAPPA90), x + w - rx * (1 - KAPPA90), y, x + w - rx, y);
|
||||
ctx.lineTo(x + rx, y);
|
||||
ctx.bezierCurveTo(x + rx * (1 - KAPPA90), y, x, y + ry * (1 - KAPPA90), x, y + ry);
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
arc: arc,
|
||||
ellipse: ellipse,
|
||||
roundRect: roundRect,
|
||||
};
|
||||
@@ -358,6 +358,8 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
if (!extName) {
|
||||
this._fontHandle = fontHandle;
|
||||
this._labelType = _ccsg.Label.Type.SystemFont;
|
||||
this._blendFunc = cc.BlendFunc._alphaPremultiplied();
|
||||
this._renderCmd._needDraw = true;
|
||||
this._notifyLabelSkinDirty();
|
||||
this.emit('load');
|
||||
return;
|
||||
@@ -365,10 +367,14 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
|
||||
if (extName === ".ttf") {
|
||||
this._labelType = _ccsg.Label.Type.TTF;
|
||||
this._blendFunc = cc.BlendFunc._alphaPremultiplied();
|
||||
this._renderCmd._needDraw = true;
|
||||
this._fontHandle = this._loadTTFFont(fontHandle);
|
||||
} else if (extName === ".fnt") {
|
||||
//todo add bmfont here
|
||||
this._labelType = _ccsg.Label.Type.BMFont;
|
||||
this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
|
||||
this._renderCmd._needDraw = false;
|
||||
this._initBMFontWithString(this._string, fontHandle, textureUrl);
|
||||
}
|
||||
this._notifyLabelSkinDirty();
|
||||
@@ -484,7 +490,7 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
if (CC_EDITOR) {
|
||||
this._updateLabel();
|
||||
} else {
|
||||
this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty);
|
||||
this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty|_ccsg.Node._dirtyFlags.contentDirty);
|
||||
}
|
||||
},
|
||||
_createRenderCmd: function() {
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
if (opacityDirty)
|
||||
this._updateDisplayOpacity();
|
||||
|
||||
if(locFlag & dirtyFlags.contentDirty) {
|
||||
this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty);
|
||||
this._dirtyFlag &= ~dirtyFlags.contentDirty;
|
||||
}
|
||||
|
||||
if (colorDirty || opacityDirty || (locFlag & flags.textDirty)) {
|
||||
this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty);
|
||||
this._rebuildLabelSkin();
|
||||
@@ -112,10 +117,11 @@
|
||||
maxWidth -= 2 * this._getMargin();
|
||||
var wrappedWords = [];
|
||||
//fast return if strArr is empty
|
||||
if(strArr.length === 0) {
|
||||
if(strArr.length === 0 || maxWidth < 0) {
|
||||
wrappedWords.push('');
|
||||
return wrappedWords;
|
||||
}
|
||||
|
||||
var text = strArr;
|
||||
var allWidth = ctx.measureText(text).width;
|
||||
while (allWidth > maxWidth && text.length > 1) {
|
||||
@@ -217,6 +223,11 @@
|
||||
|
||||
var canvasWidthNoMargin = this._canvasSize.width - 2 * this._getMargin();
|
||||
var canvasHeightNoMargin = this._canvasSize.height - 2 * this._getMargin();
|
||||
if(canvasWidthNoMargin < 0 || canvasHeightNoMargin < 0) {
|
||||
fontDesc = '1px ' + fontFamily;
|
||||
this._labelContext.font = fontDesc;
|
||||
return fontDesc;
|
||||
}
|
||||
totalHeight = canvasHeightNoMargin + 1;
|
||||
maxLength = canvasWidthNoMargin + 1;
|
||||
var actualFontSize = this._drawFontsize + 1;
|
||||
@@ -246,7 +257,6 @@
|
||||
textFragment = this._fragmentText(paragraphedStrings[i],
|
||||
canvasWidthNoMargin,
|
||||
this._labelContext);
|
||||
var isBiggerSize = false;
|
||||
while(j < textFragment.length) {
|
||||
var measureWidth = this._labelContext.measureText(textFragment[j]).width;
|
||||
maxLength = measureWidth;
|
||||
@@ -466,7 +476,7 @@
|
||||
}
|
||||
|
||||
this._texture._textureLoaded = false;
|
||||
this._texture.handleLoadedTexture();
|
||||
this._texture.handleLoadedTexture(true);
|
||||
};
|
||||
|
||||
proto._rebuildLabelSkin = function () {
|
||||
|
||||
@@ -69,7 +69,8 @@ proto._updateDisplayOpacity = function (parentOpacity) {
|
||||
proto.transform = function (parentCmd, recursive) {
|
||||
this.originTransform(parentCmd, recursive);
|
||||
|
||||
var lx = 0, rx = this._labelCanvas.width,
|
||||
var node = this._node,
|
||||
lx = 0, rx = this._labelCanvas.width,
|
||||
by = 0, ty = this._labelCanvas.height,
|
||||
wt = this._worldTransform;
|
||||
|
||||
@@ -83,6 +84,12 @@ proto.transform = function (parentCmd, recursive) {
|
||||
vert[3].x = rx * wt.a + by * wt.c + wt.tx; // br
|
||||
vert[3].y = rx * wt.b + by * wt.d + wt.ty;
|
||||
|
||||
if (!node._string || (node._labelType !== _ccsg.Label.Type.TTF &&
|
||||
node._labelType !== _ccsg.Label.Type.SystemFont)) {
|
||||
// No culling for bmfont
|
||||
return;
|
||||
}
|
||||
|
||||
var rect = cc.visibleRect,
|
||||
vl = rect.left.x, vr = rect.right.x, vt = rect.top.y, vb = rect.bottom.y;
|
||||
if (((vert[0].x-vl) & (vert[1].x-vl) & (vert[2].x-vl) & (vert[3].x-vl)) >> 31 || // All outside left
|
||||
@@ -104,17 +111,11 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
|
||||
return 0;
|
||||
|
||||
// Fill in vertex data with quad information (4 vertices for sprite)
|
||||
// Use 255 because color has been set when baking label
|
||||
// premultiplied alpha is used for labelTTF and system font
|
||||
var opacity = this._displayedOpacity;
|
||||
var r = this._displayedColor.r,
|
||||
g = this._displayedColor.g,
|
||||
b = this._displayedColor.b;
|
||||
if (node._opacityModifyRGB) {
|
||||
var a = opacity / 255;
|
||||
r *= a;
|
||||
g *= a;
|
||||
b *= a;
|
||||
}
|
||||
this._color[0] = ((opacity<<24) | (b<<16) | (g<<8) | r);
|
||||
this._color[0] = ((opacity<<24) | (opacity<<16) | (opacity<<8) | opacity);
|
||||
|
||||
var z = node._vertexZ;
|
||||
|
||||
var vertices = this._vertices;
|
||||
|
||||
@@ -29,9 +29,8 @@ var Downloader = require('./downloader');
|
||||
var Loader = require('./loader');
|
||||
var AssetTable = require('./asset-table');
|
||||
var callInNextTick = require('../platform/utils').callInNextTick;
|
||||
var AutoReleaseUtils = require('./auto-release-utils');
|
||||
|
||||
var downloader = new Downloader();
|
||||
var loader = new Loader();
|
||||
var resources = new AssetTable();
|
||||
|
||||
/**
|
||||
@@ -40,13 +39,15 @@ var resources = new AssetTable();
|
||||
* @extends Pipeline
|
||||
* @static
|
||||
*/
|
||||
cc.loader = new Pipeline([
|
||||
downloader,
|
||||
loader
|
||||
]);
|
||||
function CCLoader () {
|
||||
var downloader = new Downloader();
|
||||
var loader = new Loader();
|
||||
|
||||
Pipeline.call(this, [
|
||||
downloader,
|
||||
loader
|
||||
]);
|
||||
|
||||
JS.mixin(cc.loader, {
|
||||
/**
|
||||
* The downloader in cc.loader's pipeline, it's by default the first pipe.
|
||||
* It's used to download files with several handlers: pure text, image, script, audio, font, uuid.
|
||||
@@ -54,7 +55,7 @@ JS.mixin(cc.loader, {
|
||||
* @property downloader
|
||||
* @type {Object}
|
||||
*/
|
||||
downloader: downloader,
|
||||
this.downloader = downloader;
|
||||
|
||||
/**
|
||||
* The downloader in cc.loader's pipeline, it's by default the second pipe.
|
||||
@@ -63,7 +64,13 @@ JS.mixin(cc.loader, {
|
||||
* @property loader
|
||||
* @type {Object}
|
||||
*/
|
||||
loader: loader,
|
||||
this.loader = loader;
|
||||
|
||||
// assets to release automatically
|
||||
this._autoReleaseSetting = {};
|
||||
}
|
||||
JS.extend(CCLoader, Pipeline);
|
||||
JS.mixin(CCLoader.prototype, {
|
||||
|
||||
/**
|
||||
* Get XMLHttpRequest.
|
||||
@@ -82,7 +89,7 @@ JS.mixin(cc.loader, {
|
||||
* @param {Object} extMap Custom supported types with corresponded handler
|
||||
*/
|
||||
addDownloadHandlers: function (extMap) {
|
||||
downloader.addHandlers(extMap);
|
||||
this.downloader.addHandlers(extMap);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -96,7 +103,7 @@ JS.mixin(cc.loader, {
|
||||
* @param {Object} extMap Custom supported types with corresponded handler
|
||||
*/
|
||||
addLoadHandlers: function (extMap) {
|
||||
loader.addHandlers(extMap);
|
||||
this.loader.addHandlers(extMap);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -295,7 +302,8 @@ JS.mixin(cc.loader, {
|
||||
completeCallback = type;
|
||||
type = null;
|
||||
}
|
||||
var uuid = this._getResUuid(url, type);
|
||||
var self = this;
|
||||
var uuid = self._getResUuid(url, type);
|
||||
if (uuid) {
|
||||
this.load(
|
||||
{
|
||||
@@ -303,7 +311,15 @@ JS.mixin(cc.loader, {
|
||||
type: 'uuid',
|
||||
uuid: uuid
|
||||
},
|
||||
completeCallback
|
||||
function (err, asset) {
|
||||
if (asset) {
|
||||
// should not release these assets, even if they are static referenced in the scene.
|
||||
self.setAutoReleaseRecursively(asset, false);
|
||||
}
|
||||
if (completeCallback) {
|
||||
completeCallback(err, asset);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -315,7 +331,9 @@ JS.mixin(cc.loader, {
|
||||
else {
|
||||
info = 'Resources url "' + url + '" does not exist.';
|
||||
}
|
||||
completeCallback(new Error(info), null);
|
||||
if (completeCallback) {
|
||||
completeCallback(new Error(info), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -360,6 +378,7 @@ JS.mixin(cc.loader, {
|
||||
completeCallback = type;
|
||||
type = null;
|
||||
}
|
||||
var self = this;
|
||||
var uuids = resources.getUuidArray(url, type);
|
||||
var remain = uuids.length;
|
||||
if (remain > 0) {
|
||||
@@ -371,18 +390,25 @@ JS.mixin(cc.loader, {
|
||||
}
|
||||
if (err) {
|
||||
aborted = true;
|
||||
completeCallback(err, null);
|
||||
if (completeCallback) {
|
||||
completeCallback(err, null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
results.push(res);
|
||||
--remain;
|
||||
if (remain === 0) {
|
||||
completeCallback(null, results);
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
self.setAutoReleaseRecursively(results[i], false);
|
||||
}
|
||||
if (completeCallback) {
|
||||
completeCallback(null, results);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var i = 0, len = remain; i < len; ++i) {
|
||||
var uuid = uuids[i];
|
||||
this.load(
|
||||
self.load(
|
||||
{
|
||||
id: uuid,
|
||||
type: 'uuid',
|
||||
@@ -394,7 +420,9 @@ JS.mixin(cc.loader, {
|
||||
}
|
||||
else {
|
||||
callInNextTick(function () {
|
||||
completeCallback(null, []);
|
||||
if (completeCallback) {
|
||||
completeCallback(null, []);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -429,7 +457,7 @@ JS.mixin(cc.loader, {
|
||||
/**
|
||||
* Returns an item in pipeline.
|
||||
* @method getItem
|
||||
* @return {LoadingItem}
|
||||
* @return {Object}
|
||||
*/
|
||||
getItem: function (url) {
|
||||
var item = this._items.map[url];
|
||||
@@ -489,9 +517,131 @@ JS.mixin(cc.loader, {
|
||||
*/
|
||||
releaseAll: function () {
|
||||
this.clear();
|
||||
}
|
||||
},
|
||||
|
||||
// AUTO RELEASE
|
||||
|
||||
_baseRemoveItem: Pipeline.prototype.removeItem,
|
||||
|
||||
// override
|
||||
removeItem: function (key) {
|
||||
var removed = this._baseRemoveItem(key);
|
||||
delete this._autoReleaseSetting[key];
|
||||
return removed;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Indicates whether to release the asset when loading a new scene.<br>
|
||||
* By default, when loading a new scene, all assets in the previous scene will be released or preserved
|
||||
* according to whether the previous scene checked the "Auto Release Assets" option.
|
||||
* On the other hand, assets dynamically loaded by using `cc.loader.loadRes` or `cc.loader.loadResAll`
|
||||
* will not be affected by that option, remain not released by default.<br>
|
||||
* Use this API to change the default behavior on a single asset, to force preserve or release specified asset when scene switching.<br>
|
||||
* <br>
|
||||
* See: {{#crossLink "loader/setAutoReleaseRecursively:method"}}cc.loader.setAutoReleaseRecursively{{/crossLink}}, {{#crossLink "loader/isAutoRelease:method"}}cc.loader.isAutoRelease{{/crossLink}}
|
||||
* !#zh
|
||||
* 设置当场景切换时是否自动释放资源。<br>
|
||||
* 默认情况下,当加载新场景时,旧场景的资源根据旧场景是否勾选“Auto Release Assets”,将会被释放或者保留。
|
||||
* 而使用 `cc.loader.loadRes` 或 `cc.loader.loadResAll` 动态加载的资源,则不受场景设置的影响,默认不自动释放。<br>
|
||||
* 使用这个 API 可以在单个资源上改变这个默认行为,强制在切换场景时保留或者释放指定资源。<br>
|
||||
* <br>
|
||||
* 参考:{{#crossLink "loader/setAutoReleaseRecursively:method"}}cc.loader.setAutoReleaseRecursively{{/crossLink}},{{#crossLink "loader/isAutoRelease:method"}}cc.loader.isAutoRelease{{/crossLink}}
|
||||
*
|
||||
* @example
|
||||
* // auto release the texture event if "Auto Release Assets" disabled in current scene
|
||||
* cc.loader.setAutoRelease(texture2d, true);
|
||||
* // don't release the texture even if "Auto Release Assets" enabled in current scene
|
||||
* cc.loader.setAutoRelease(texture2d, false);
|
||||
* // first parameter can be url
|
||||
* cc.loader.setAutoRelease(audioUrl, false);
|
||||
*
|
||||
* @method setAutoRelease
|
||||
* @param {Asset|String} assetOrUrl - asset object or the raw asset's url
|
||||
* @param {Boolean} autoRelease - indicates whether should release automatically
|
||||
*/
|
||||
setAutoRelease: function (assetOrUrl, autoRelease) {
|
||||
var key = AutoReleaseUtils.getKey(this, assetOrUrl);
|
||||
if (key) {
|
||||
this._autoReleaseSetting[key] = !!autoRelease;
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.warn('No need to release non-cached asset.');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Indicates whether to release the asset and its referenced other assets when loading a new scene.<br>
|
||||
* By default, when loading a new scene, all assets in the previous scene will be released or preserved
|
||||
* according to whether the previous scene checked the "Auto Release Assets" option.
|
||||
* On the other hand, assets dynamically loaded by using `cc.loader.loadRes` or `cc.loader.loadResAll`
|
||||
* will not be affected by that option, remain not released by default.<br>
|
||||
* Use this API to change the default behavior on the specified asset and its recursively referenced assets, to force preserve or release specified asset when scene switching.<br>
|
||||
* <br>
|
||||
* See: {{#crossLink "loader/setAutoRelease:method"}}cc.loader.setAutoRelease{{/crossLink}}, {{#crossLink "loader/isAutoRelease:method"}}cc.loader.isAutoRelease{{/crossLink}}
|
||||
* !#zh
|
||||
* 设置当场景切换时是否自动释放资源及资源引用的其它资源。<br>
|
||||
* 默认情况下,当加载新场景时,旧场景的资源根据旧场景是否勾选“Auto Release Assets”,将会被释放或者保留。
|
||||
* 而使用 `cc.loader.loadRes` 或 `cc.loader.loadResAll` 动态加载的资源,则不受场景设置的影响,默认不自动释放。<br>
|
||||
* 使用这个 API 可以在指定资源及资源递归引用到的所有资源上改变这个默认行为,强制在切换场景时保留或者释放指定资源。<br>
|
||||
* <br>
|
||||
* 参考:{{#crossLink "loader/setAutoRelease:method"}}cc.loader.setAutoRelease{{/crossLink}},{{#crossLink "loader/isAutoRelease:method"}}cc.loader.isAutoRelease{{/crossLink}}
|
||||
*
|
||||
* @example
|
||||
* // auto release the SpriteFrame and its Texture event if "Auto Release Assets" disabled in current scene
|
||||
* cc.loader.setAutoReleaseRecursively(spriteFrame, true);
|
||||
* // don't release the SpriteFrame and its Texture even if "Auto Release Assets" enabled in current scene
|
||||
* cc.loader.setAutoReleaseRecursively(spriteFrame, false);
|
||||
* // don't release the Prefab and all the referenced assets
|
||||
* cc.loader.setAutoReleaseRecursively(prefab, false);
|
||||
*
|
||||
* @method setAutoReleaseRecursively
|
||||
* @param {Asset|String} assetOrUrl - asset object or the raw asset's url
|
||||
* @param {Boolean} autoRelease - indicates whether should release automatically
|
||||
*/
|
||||
setAutoReleaseRecursively: function (assetOrUrl, autoRelease) {
|
||||
autoRelease = !!autoRelease;
|
||||
var key = AutoReleaseUtils.getKey(this, assetOrUrl);
|
||||
if (key) {
|
||||
this._autoReleaseSetting[key] = autoRelease;
|
||||
|
||||
var depends = AutoReleaseUtils.getDependsRecursively(key);
|
||||
for (var i = 0; i < depends.length; i++) {
|
||||
var depend = depends[i];
|
||||
this._autoReleaseSetting[depend] = autoRelease;
|
||||
}
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.warn('No need to release non-cached asset.');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Returns whether the asset is configured as auto released, despite how "Auto Release Assets" property is set on scene asset.<br>
|
||||
* <br>
|
||||
* See: {{#crossLink "loader/setAutoRelease:method"}}cc.loader.setAutoRelease{{/crossLink}}, {{#crossLink "loader/setAutoReleaseRecursively:method"}}cc.loader.setAutoReleaseRecursively{{/crossLink}}
|
||||
*
|
||||
* !#zh
|
||||
* 返回指定的资源是否有被设置为自动释放,不论场景的“Auto Release Assets”如何设置。<br>
|
||||
* <br>
|
||||
* 参考:{{#crossLink "loader/setAutoRelease:method"}}cc.loader.setAutoRelease{{/crossLink}},{{#crossLink "loader/setAutoReleaseRecursively:method"}}cc.loader.setAutoReleaseRecursively{{/crossLink}}
|
||||
* @method isAutoRelease
|
||||
* @param {Asset|String} assetOrUrl - asset object or the raw asset's url
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isAutoRelease: function (assetOrUrl) {
|
||||
var key = AutoReleaseUtils.getKey(this, assetOrUrl);
|
||||
if (key) {
|
||||
return !!this._autoReleaseSetting[key];
|
||||
}
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
cc.loader = new CCLoader();
|
||||
|
||||
if (CC_EDITOR) {
|
||||
cc.loader.refreshUrl = function (uuid, oldUrl, newUrl) {
|
||||
this._items.refreshItemUrl(uuid, oldUrl, newUrl);
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
|
||||
function parseDepends (key, parsed) {
|
||||
var item = cc.loader.getItem(key);
|
||||
if (item) {
|
||||
var depends = item.dependKeys;
|
||||
if (depends) {
|
||||
for (var i = 0; i < depends.length; i++) {
|
||||
var depend = depends[i];
|
||||
if ( !parsed[depend] ) {
|
||||
parsed[depend] = true;
|
||||
parseDepends(depend, parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function release (loader, key, nextSceneAssets) {
|
||||
if (!nextSceneAssets || nextSceneAssets.indexOf(key) === -1) {
|
||||
var item = loader.getItem(key);
|
||||
if (item) {
|
||||
var removed = loader.removeItem(key);
|
||||
console.log('auto release: ' + key);
|
||||
// TODO: Audio
|
||||
var asset = item.content;
|
||||
if (asset instanceof cc.Texture2D) {
|
||||
cc.textureCache.removeTextureForKey(item.url);
|
||||
}
|
||||
else if (CC_JSB && asset instanceof cc.SpriteFrame && removed) {
|
||||
// for the "Temporary solution" in deserialize.js
|
||||
asset.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
// get asset url or uuid
|
||||
getKey: function (loader, assetOrUrl) {
|
||||
if (assetOrUrl) {
|
||||
if (typeof assetOrUrl === 'string') {
|
||||
return assetOrUrl;
|
||||
}
|
||||
else if (assetOrUrl instanceof cc.Asset) {
|
||||
return assetOrUrl._uuid;
|
||||
}
|
||||
else if (assetOrUrl instanceof cc.Texture2D) {
|
||||
return assetOrUrl.url;
|
||||
}
|
||||
else if (!CC_JSB && assetOrUrl instanceof cc.Audio) {
|
||||
return assetOrUrl.src;
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.warn('unknown asset type');
|
||||
}
|
||||
}
|
||||
return '';
|
||||
},
|
||||
|
||||
// do auto release
|
||||
autoRelease: function (loader, oldSceneAssets, nextSceneAssets) {
|
||||
var releaseSettings = loader._autoReleaseSetting;
|
||||
var i, key;
|
||||
|
||||
// remove ununsed scene assets
|
||||
if (oldSceneAssets) {
|
||||
for (i = 0; i < oldSceneAssets.length; i++) {
|
||||
key = oldSceneAssets[i];
|
||||
if (releaseSettings[key] !== false) {
|
||||
release(loader, key, nextSceneAssets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove auto release assets
|
||||
var keys = Object.keys(releaseSettings);
|
||||
// releasing asset will change _autoReleaseSetting, so don't use enumerator
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
key = keys[i];
|
||||
if (releaseSettings[key] === true) {
|
||||
release(loader, key, nextSceneAssets);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// get dependencies not including self
|
||||
getDependsRecursively: function (key) {
|
||||
var depends = {};
|
||||
parseDepends(key, depends);
|
||||
return Object.keys(depends);
|
||||
}
|
||||
};
|
||||
@@ -509,6 +509,7 @@ JS.mixin(Pipeline.prototype, {
|
||||
this.flowOut(item);
|
||||
}
|
||||
this._items.removeItem(url);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
||||
@@ -97,6 +97,9 @@ function loadDepends (pipeline, item, asset, tdInfo, deferredLoadRawAssetsInRunt
|
||||
return callback(null, asset);
|
||||
}
|
||||
|
||||
// cache dependencies for auto release
|
||||
var dependKeys = item.dependKeys = [];
|
||||
|
||||
pipeline.flowInDeps(depends, function (items) {
|
||||
var item;
|
||||
for (var src in items) {
|
||||
@@ -114,12 +117,14 @@ function loadDepends (pipeline, item, asset, tdInfo, deferredLoadRawAssetsInRunt
|
||||
if (item.complete) {
|
||||
var value = item.isRawAsset ? item.url : item.content;
|
||||
dependObj[dependProp] = value;
|
||||
dependKeys.push(item.isRawAsset ? item.url : dependSrc);
|
||||
}
|
||||
else {
|
||||
// item was removed from cache, but ready in pipeline actually
|
||||
var loadCallback = function (item) {
|
||||
var value = item.isRawAsset ? item.url : item.content;
|
||||
this.obj[this.prop] = value;
|
||||
dependKeys.push(item.isRawAsset ? item.url : item.uuid);
|
||||
};
|
||||
var target = {
|
||||
obj: dependObj,
|
||||
@@ -159,9 +164,9 @@ function canDeferredLoad (asset, item, isScene) {
|
||||
else if (isScene) {
|
||||
if (asset instanceof cc.SceneAsset) {
|
||||
res = asset.asyncLoadAssets;
|
||||
if (res) {
|
||||
cc.log('deferred load raw assets for ' + item.id);
|
||||
}
|
||||
//if (res) {
|
||||
// cc.log('deferred load raw assets for ' + item.id);
|
||||
//}
|
||||
}
|
||||
//else if (asset instanceof cc.Scene) {
|
||||
// deferredLoadRawAssetsInRuntime = asset._asyncLoadAssets;
|
||||
@@ -210,7 +215,8 @@ function loadUuid (item, callback) {
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
callback( new Error('Uuid Loader: Deserialize asset [' + item.id + '] failed : ' + e.stack) );
|
||||
var err = CC_JSB ? (e + '\n' + e.stack) : e.stack;
|
||||
callback( new Error('Uuid Loader: Deserialize asset [' + item.id + '] failed : ' + err) );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ var Asset = require('../assets/CCAsset');
|
||||
var callInNextTick = require('./utils').callInNextTick;
|
||||
var Loader = require('../load-pipeline/CCLoader');
|
||||
var PackDownloader = require('../load-pipeline/pack-downloader');
|
||||
var AutoReleaseUtils = require('../load-pipeline/auto-release-utils');
|
||||
|
||||
/**
|
||||
* The asset library which managing loading/unloading assets in project.
|
||||
@@ -67,6 +68,9 @@ var AssetLibrary = {
|
||||
* @private
|
||||
*/
|
||||
loadAsset: function (uuid, callback, options) {
|
||||
if (typeof uuid !== 'string') {
|
||||
return callInNextTick(callback, new Error('[AssetLibrary] uuid must be string'), null);
|
||||
}
|
||||
// var readMainCache = typeof (options && options.readMainCache) !== 'undefined' ? readMainCache : true;
|
||||
// var writeMainCache = typeof (options && options.writeMainCache) !== 'undefined' ? writeMainCache : true;
|
||||
var item = {
|
||||
@@ -79,7 +83,22 @@ var AssetLibrary = {
|
||||
if (options && options.existingAsset) {
|
||||
item.existingAsset = options.existingAsset;
|
||||
}
|
||||
this._loadAssetByUuid(item, callback);
|
||||
Loader.load(item, function (error, asset) {
|
||||
if (error || !asset) {
|
||||
error = new Error('[AssetLibrary] loading JSON or dependencies failed: ' + error.message);
|
||||
}
|
||||
else {
|
||||
if (asset.constructor === cc.SceneAsset) {
|
||||
asset.scene.dependAssets = AutoReleaseUtils.getDependsRecursively(uuid);
|
||||
}
|
||||
if (CC_EDITOR || isScene(asset)) {
|
||||
Loader.removeItem(uuid);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(error, asset);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getImportedDir: function (uuid) {
|
||||
@@ -170,36 +189,6 @@ var AssetLibrary = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#zh uuid加载流程:
|
||||
* 1. 查找_uuidToAsset,如果已经加载过,直接返回
|
||||
* 2. 查找_uuidToCallbacks,如果已经在加载,则注册回调,直接返回
|
||||
* 3. 如果没有url,则将uuid直接作为路径
|
||||
* 4. 递归加载Asset及其引用到的其它Asset
|
||||
*
|
||||
* @method _loadAssetByUuid
|
||||
* @param {Object} item - loading item including uuid, type and extra infos
|
||||
* @param {loadCallback} callback - the callback to receive the asset, can be null
|
||||
* @private
|
||||
*/
|
||||
_loadAssetByUuid: function (item, callback) {
|
||||
var uuid = item.id;
|
||||
if (typeof uuid !== 'string') {
|
||||
return callInNextTick(callback, new Error('[AssetLibrary] uuid must be string'), null);
|
||||
}
|
||||
Loader.load(item, function (error, asset) {
|
||||
if (error || !asset) {
|
||||
error = new Error('[AssetLibrary] loading JSON or dependencies failed: ' + error.message);
|
||||
}
|
||||
else if (CC_EDITOR || isScene(asset)) {
|
||||
Loader.removeItem(uuid);
|
||||
}
|
||||
if (callback) {
|
||||
callback(error, asset);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadJson
|
||||
* @param {String} json
|
||||
@@ -219,8 +208,13 @@ var AssetLibrary = {
|
||||
if (error) {
|
||||
error = new Error('[AssetLibrary] loading JSON or dependencies failed: ' + error.message);
|
||||
}
|
||||
else if (CC_EDITOR || isScene(asset)) {
|
||||
Loader.removeItem(randomUuid);
|
||||
else {
|
||||
if (asset.constructor === cc.SceneAsset) {
|
||||
asset.scene.dependAssets = AutoReleaseUtils.getDependsRecursively(randomUuid);
|
||||
}
|
||||
if (CC_EDITOR || isScene(asset)) {
|
||||
Loader.removeItem(randomUuid);
|
||||
}
|
||||
}
|
||||
asset._uuid = '';
|
||||
if (callback) {
|
||||
|
||||
@@ -458,21 +458,21 @@ function define (className, baseClasses, mixins, constructor, options) {
|
||||
return doDefine(className, baseClasses, mixins, constructor, options);
|
||||
}
|
||||
|
||||
function _checkCtor (ctor) {
|
||||
function _checkCtor (ctor, className) {
|
||||
if (CC_DEV) {
|
||||
if (CCClass._isCCClass(ctor)) {
|
||||
cc.error("Constructor can not be another CCClass");
|
||||
cc.error('ctor of "%s" can not be another CCClass', className);
|
||||
return;
|
||||
}
|
||||
if (typeof ctor !== 'function') {
|
||||
cc.error("Constructor of CCClass must be function type");
|
||||
cc.error('ctor of "%s" must be function type', className);
|
||||
return;
|
||||
}
|
||||
if (ctor.length > 0) {
|
||||
// fireball-x/dev#138: To make a unified CCClass serialization process,
|
||||
// we don't allow parameters for constructor when creating instances of CCClass.
|
||||
// For advance user, construct arguments can still get from 'arguments'.
|
||||
cc.warn("Can not instantiate CCClass with arguments.");
|
||||
cc.warn('Can not instantiate CCClass "%s" with arguments.', className);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -530,7 +530,7 @@ function _createCtor (ctor, baseClass, mixins, className, options) {
|
||||
var superCallBounded = options && baseClass && boundSuperCalls(baseClass, options);
|
||||
|
||||
if (ctor && CC_DEV) {
|
||||
_checkCtor(ctor);
|
||||
_checkCtor(ctor, className);
|
||||
}
|
||||
// get base user constructors
|
||||
var ctors = [];
|
||||
@@ -614,21 +614,21 @@ function _boundSuperCall (func, funcName, base) {
|
||||
var pd = JS.getPropertyDescriptor(base.prototype, funcName);
|
||||
if (pd) {
|
||||
superFunc = pd.value;
|
||||
// ignore pd.get, assume that function defined by getter is just for warnings
|
||||
// ignore pd.get, assume that function defined by getter is just for warnings
|
||||
if (typeof superFunc === 'function') {
|
||||
var hasSuperCall = SuperCallReg.test(func);
|
||||
if (hasSuperCall) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
|
||||
// Add a new ._super() method that is the same method but on the super-Class
|
||||
this._super = superFunc;
|
||||
|
||||
|
||||
var ret = func.apply(this, arguments);
|
||||
|
||||
|
||||
// The method only need to be bound temporarily, so we remove it when we're done executing
|
||||
this._super = tmp;
|
||||
|
||||
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
@@ -689,72 +689,6 @@ function declareProperties (cls, className, properties, baseClass, mixins) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @class _ComponentAttributes
|
||||
* @constructor
|
||||
*/
|
||||
/**
|
||||
* Automatically add required component as a dependency.
|
||||
*
|
||||
* @property requireComponent
|
||||
* @type {Component}
|
||||
* @default null
|
||||
*/
|
||||
/**
|
||||
* If specified to a type, prevents Component of the same type (or subtype) to be added more than once to a Node.
|
||||
*
|
||||
* @property disallowMultiple
|
||||
* @type {Component}
|
||||
* @default null
|
||||
*/
|
||||
/**
|
||||
* The menu path to register a component to the editors "Component" menu. Eg. "Rendering/Camera".
|
||||
*
|
||||
* @property menu
|
||||
* @type {String}
|
||||
* @default ""
|
||||
*/
|
||||
/**
|
||||
* Makes a component execute in edit mode.
|
||||
* By default, all components are only executed in play mode,
|
||||
* which means they will not have their callback functions executed while the Editor is in edit mode.
|
||||
*
|
||||
* @property executeInEditMode
|
||||
* @type {Boolean}
|
||||
* @default false
|
||||
*/
|
||||
/**
|
||||
* This property is only available if executeInEditMode is true.
|
||||
* If specified, the editor's scene view will keep updating this node in 60 fps when it is selected,
|
||||
* otherwise, it will update only if necessary.
|
||||
*
|
||||
* @property playOnFocus
|
||||
* @type {Boolean}
|
||||
* @default false
|
||||
*/
|
||||
/**
|
||||
* Specifying the url of the custom html to draw the component in inspector.
|
||||
*
|
||||
* @property inspector
|
||||
* @type {String}
|
||||
* @default ""
|
||||
*/
|
||||
/**
|
||||
* Specifying the url of the icon to display in inspector.
|
||||
*
|
||||
* @property icon
|
||||
* @type {String}
|
||||
* @default ""
|
||||
*/
|
||||
|
||||
/**
|
||||
* The custom documentation URL
|
||||
*
|
||||
* @property help
|
||||
* @type {String}
|
||||
* @default ""
|
||||
*/
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
@@ -762,9 +696,9 @@ function declareProperties (cls, className, properties, baseClass, mixins) {
|
||||
/**
|
||||
* !#en Defines a CCClass using the given specification, please see [Class](/en/scripting/class/) for details.
|
||||
* !#zh 定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/zh/scripting/class/)。
|
||||
*
|
||||
*
|
||||
* @method Class
|
||||
*
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {String} [options.name] - The class name used for serialization.
|
||||
* @param {Function} [options.extends] - The base class.
|
||||
@@ -772,9 +706,17 @@ function declareProperties (cls, className, properties, baseClass, mixins) {
|
||||
* @param {Object} [options.properties] - The property definitions.
|
||||
* @param {Object} [options.statics] - The static members.
|
||||
* @param {Function[]} [options.mixins]
|
||||
*
|
||||
* @param {Object} [options.editor] - attributes for Component, see {{#crossLink "_ComponentAttributes"}}ComponentAttributes{{/crossLink}}.
|
||||
*
|
||||
*
|
||||
* @param {Object} [options.editor] - attributes for Component listed below.
|
||||
* @param {Component} [options.editor.requireComponent] - Automatically add required component as a dependency.
|
||||
* @param {Component} [options.editor.disallowMultiple] - If specified to a type, prevents Component of the same type (or subtype) to be added more than once to a Node.
|
||||
* @param {String} [options.editor.menu] - The menu path to register a component to the editors "Component" menu. Eg. "Rendering/Camera".
|
||||
* @param {Boolean} [options.editor.executeInEditMode] - Makes a component execute in edit mode. By default, all components are only executed in play mode, which means they will not have their callback functions executed while the Editor is in edit mode.
|
||||
* @param {Boolean} [options.editor.playOnFocus] - This property is only available if executeInEditMode is true. If specified, the editor's scene view will keep updating this node in 60 fps when it is selected, otherwise, it will update only if necessary.
|
||||
* @param {String} [options.editor.inspector] - Specifying the url of the custom html to draw the component in inspector.
|
||||
* @param {String} [options.editor.icon] - Specifying the url of the icon to display in inspector.
|
||||
* @param {String} [options.editor.help] - The custom documentation UR
|
||||
*
|
||||
* @param {Function} [options.update] - lifecycle method for Component, see {{#crossLink "Component/update:method"}}{{/crossLink}}
|
||||
* @param {Function} [options.lateUpdate] - lifecycle method for Component, see {{#crossLink "Component/lateUpdate:method"}}{{/crossLink}}
|
||||
* @param {Function} [options.onLoad] - lifecycle method for Component, see {{#crossLink "Component/onLoad:method"}}{{/crossLink}}
|
||||
@@ -786,9 +728,9 @@ function declareProperties (cls, className, properties, baseClass, mixins) {
|
||||
* @param {Function} [options.onLostFocusInEditor] - lifecycle method for Component, see {{#crossLink "Component/onLostFocusInEditor:method"}}{{/crossLink}}
|
||||
* @param {Function} [options.onRestore] - for Component only, see {{#crossLink "Component/onRestore:method"}}{{/crossLink}}
|
||||
* @param {Function} [options._getLocalBounds] - for Component only, see {{#crossLink "Component/_getLocalBounds:method"}}{{/crossLink}}
|
||||
*
|
||||
*
|
||||
* @return {Function} - the created class
|
||||
*
|
||||
*
|
||||
* @example
|
||||
// define base class
|
||||
var Node = cc.Class();
|
||||
@@ -906,6 +848,15 @@ function CCClass (options) {
|
||||
});
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
if (func === false && base && base.prototype) {
|
||||
// check override
|
||||
var overrided = base.prototype[funcName];
|
||||
if (typeof overrided === 'function') {
|
||||
var baseFuc = JS.getClassName(base) + '.' + funcName;
|
||||
var subFuc = name + '.' + funcName;
|
||||
cc.warn('"%s" overrided "%s" but "%s" is defined as "false" so the super method will not be called. You can set "%s" to null to disable this warning.', subFuc, baseFuc, subFuc, subFuc);
|
||||
}
|
||||
}
|
||||
var correct = TYPO_TO_CORRECT[funcName];
|
||||
if (correct) {
|
||||
cc.warn('Unknown type of %s.%s, maybe you want is "%s".', name, funcName, correct);
|
||||
@@ -1052,10 +1003,10 @@ function parseAttributes (attrs, className, propName) {
|
||||
}
|
||||
|
||||
function parseSimpleAttr (attrName, expectType, attrCreater) {
|
||||
var val = attrs[attrName];
|
||||
if (val) {
|
||||
if (attrName in attrs) {
|
||||
var val = attrs[attrName];
|
||||
if (typeof val === expectType) {
|
||||
if (typeof attrCreater === 'undefined') {
|
||||
if ( !attrCreater ) {
|
||||
var attr = {};
|
||||
attr[attrName] = val;
|
||||
result.push(attr);
|
||||
@@ -1065,7 +1016,7 @@ function parseAttributes (attrs, className, propName) {
|
||||
}
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.error('The %s of %s.%s must be type %s', attrName, className, propName, expectType);
|
||||
cc.error(ERR_Type, attrName, className, propName, expectType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1119,13 +1070,16 @@ function parseAttributes (attrs, className, propName) {
|
||||
result.push({ min: range[0], max: range[1], step: range[2] });
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.error('The length of range array must be 2');
|
||||
cc.error('The length of range array must be equal or greater than 2');
|
||||
}
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.error(ERR_Type, '"range"', className + '.' + propName, 'array');
|
||||
cc.error(ERR_Type, 'range', className, propName, 'array');
|
||||
}
|
||||
}
|
||||
parseSimpleAttr('min', 'number');
|
||||
parseSimpleAttr('max', 'number');
|
||||
parseSimpleAttr('step', 'number');
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1142,5 +1096,5 @@ module.exports = {
|
||||
};
|
||||
|
||||
if (CC_EDITOR) {
|
||||
module.exports.getDefault = getDefault;
|
||||
module.exports.getDefault = getDefault;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ sys.MACOS = 2;
|
||||
*/
|
||||
sys.ANDROID = 3;
|
||||
/**
|
||||
* @property {Number} IOS
|
||||
* @property {Number} IPHONE
|
||||
* @readOnly
|
||||
* @default 4
|
||||
*/
|
||||
|
||||
@@ -927,32 +927,30 @@ var View = cc._Class.extend({
|
||||
return this._isRotated ? {x: this._viewPortRect.width - y, y: x} : {x: x, y: y};
|
||||
},
|
||||
|
||||
_convertMouseToLocationInView: function(point, relatedPos) {
|
||||
var locViewPortRect = this._viewPortRect, _t = this;
|
||||
point.x = ((_t._devicePixelRatio * (point.x - relatedPos.left)) - locViewPortRect.x) / _t._scaleX;
|
||||
point.y = (_t._devicePixelRatio * (relatedPos.top + relatedPos.height - point.y) - locViewPortRect.y) / _t._scaleY;
|
||||
_convertMouseToLocationInView: function (point, relatedPos) {
|
||||
var viewport = this._viewPortRect, _t = this;
|
||||
point.x = ((_t._devicePixelRatio * (point.x - relatedPos.left)) - viewport.x) / _t._scaleX;
|
||||
point.y = (_t._devicePixelRatio * (relatedPos.top + relatedPos.height - point.y) - viewport.y) / _t._scaleY;
|
||||
},
|
||||
|
||||
_convertTouchesWithScale: function(touches){
|
||||
var locViewPortRect = this._viewPortRect, locScaleX = this._scaleX, locScaleY = this._scaleY,
|
||||
selTouch, selPoint, selPrePoint, selStartPoint;
|
||||
for( var i = 0; i < touches.length; i ++){
|
||||
_convertPointWithScale: function (point) {
|
||||
var viewport = this._viewPortRect;
|
||||
point.x = (point.x - viewport.x) / this._scaleX;
|
||||
point.y = (point.y - viewport.y) / this._scaleY;
|
||||
},
|
||||
|
||||
_convertTouchesWithScale: function (touches) {
|
||||
var viewport = this._viewPortRect, scaleX = this._scaleX, scaleY = this._scaleY,
|
||||
selTouch, selPoint, selPrePoint;
|
||||
for( var i = 0; i < touches.length; i++){
|
||||
selTouch = touches[i];
|
||||
hasStartPoint = selTouch._startPointCaptured;
|
||||
selPoint = selTouch._point;
|
||||
selPrePoint = selTouch._prevPoint;
|
||||
|
||||
selPoint.x = (selPoint.x - locViewPortRect.x) / locScaleX;
|
||||
selPoint.y = (selPoint.y - locViewPortRect.y) / locScaleY;
|
||||
selPrePoint.x = (selPrePoint.x - locViewPortRect.x) / locScaleX;
|
||||
selPrePoint.y = (selPrePoint.y - locViewPortRect.y) / locScaleY;
|
||||
|
||||
if (!hasStartPoint) {
|
||||
selStartPoint = selTouch._startPoint;
|
||||
selStartPoint.x = selPoint.x;
|
||||
selStartPoint.y = selPoint.y;
|
||||
selTouch._startPointCaptured = true;
|
||||
}
|
||||
selPoint.x = (selPoint.x - viewport.x) / scaleX;
|
||||
selPoint.y = (selPoint.y - viewport.y) / scaleY;
|
||||
selPrePoint.x = (selPrePoint.x - viewport.x) / scaleX;
|
||||
selPrePoint.y = (selPrePoint.y - viewport.y) / scaleY;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -467,12 +467,13 @@ var _Deserializer = (function () {
|
||||
* @return {object} the main data(asset)
|
||||
*/
|
||||
cc.deserialize = function (data, result, options) {
|
||||
var classFinder = (options && options.classFinder) || JS._getClassById;
|
||||
options = options || {};
|
||||
var classFinder = options.classFinder || JS._getClassById;
|
||||
// 启用 createAssetRefs 后,如果有 url 属性则会被统一强制设置为 { uuid: 'xxx' },必须后面再特殊处理
|
||||
var createAssetRefs = (options && options.createAssetRefs) || cc.sys.platform === cc.sys.EDITOR_CORE;
|
||||
var target = CC_DEV && (options && options.target);
|
||||
var customEnv = options && options.customEnv;
|
||||
var ignoreEditorOnly = options && options.ignoreEditorOnly;
|
||||
var createAssetRefs = options.createAssetRefs || cc.sys.platform === cc.sys.EDITOR_CORE;
|
||||
var target = CC_DEV && options.target;
|
||||
var customEnv = options.customEnv;
|
||||
var ignoreEditorOnly = options.ignoreEditorOnly;
|
||||
|
||||
if (CC_EDITOR && Buffer.isBuffer(data)) {
|
||||
data = data.toString();
|
||||
|
||||
@@ -33,20 +33,17 @@ var PrefabInfo = cc.Class({
|
||||
//},
|
||||
|
||||
// the most top node of this prefab in the scene
|
||||
root: {
|
||||
default: null,
|
||||
},
|
||||
root: null,
|
||||
|
||||
// 所属的 prefab 资源对象 (cc.Prefab)
|
||||
// (这个属性在场景中是会保存的,但是不会保存在 prefab 里面,因为创建 prefab 时还不知道自己的 uuid 是多少。)
|
||||
asset: {
|
||||
default: null,
|
||||
},
|
||||
asset: null,
|
||||
|
||||
// 用来标识别该节点在 prefab 资源中的位置,因此这个 ID 只需要保证在 Assets 里不重复就行
|
||||
fileId: {
|
||||
default: ''
|
||||
},
|
||||
fileId: '',
|
||||
|
||||
//// Indicates whether this node should always synchronize with the prefab asset.
|
||||
//sync: false,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ var _batchedInfo = {
|
||||
shader: null
|
||||
},
|
||||
|
||||
_batchBroken = false,
|
||||
_indexBuffer = null,
|
||||
_vertexBuffer = null,
|
||||
// Total vertex size
|
||||
@@ -302,6 +303,10 @@ cc.rendererWebGL = {
|
||||
_batchingSize += increment;
|
||||
},
|
||||
|
||||
_breakBatch: function () {
|
||||
_batchBroken = true;
|
||||
},
|
||||
|
||||
_uploadBufferData: function (cmd) {
|
||||
if (_batchingSize >= _maxVertexSize) {
|
||||
this._batchRendering();
|
||||
@@ -313,7 +318,8 @@ cc.rendererWebGL = {
|
||||
var blendSrc = cmd._node._blendFunc.src;
|
||||
var blendDst = cmd._node._blendFunc.dst;
|
||||
var shader = cmd._shaderProgram;
|
||||
if (_batchedInfo.texture !== texture ||
|
||||
if (_batchBroken ||
|
||||
_batchedInfo.texture !== texture ||
|
||||
_batchedInfo.blendSrc !== blendSrc ||
|
||||
_batchedInfo.blendDst !== blendDst ||
|
||||
_batchedInfo.shader !== shader) {
|
||||
@@ -324,6 +330,7 @@ cc.rendererWebGL = {
|
||||
_batchedInfo.blendSrc = blendSrc;
|
||||
_batchedInfo.blendDst = blendDst;
|
||||
_batchedInfo.shader = shader;
|
||||
_batchBroken = false;
|
||||
}
|
||||
|
||||
// Upload vertex data
|
||||
|
||||
@@ -484,28 +484,6 @@ var fillQuadGeneratorBar = {
|
||||
sprite._uvs = uvs;
|
||||
}
|
||||
|
||||
//build quads
|
||||
if (webgl) {
|
||||
vertices[0] = l * wt.a + b * wt.c + wt.tx;
|
||||
vertices[1] = l * wt.b + b * wt.d + wt.ty;
|
||||
vertices[2] = r * wt.a + b * wt.c + wt.tx;
|
||||
vertices[3] = r * wt.b + b * wt.d + wt.ty;
|
||||
vertices[4] = l * wt.a + t * wt.c + wt.tx;
|
||||
vertices[5] = l * wt.b + t * wt.d + wt.ty;
|
||||
vertices[6] = r * wt.a + t * wt.c + wt.tx;
|
||||
vertices[7] = r * wt.b + t * wt.d + wt.ty;
|
||||
}
|
||||
else {
|
||||
vertices[0] = l;
|
||||
vertices[1] = b;
|
||||
vertices[2] = r;
|
||||
vertices[3] = b;
|
||||
vertices[4] = l;
|
||||
vertices[5] = t;
|
||||
vertices[6] = r;
|
||||
vertices[7] = t;
|
||||
}
|
||||
|
||||
var quadUV = new Array(8);
|
||||
if (!spriteFrame._rotated) {
|
||||
quadUV[0] = quadUV[4] = ul;
|
||||
@@ -533,13 +511,11 @@ var fillQuadGeneratorBar = {
|
||||
var progressStart, progressEnd;
|
||||
switch (fillType) {
|
||||
case FillType.HORIZONTAL:
|
||||
progressStart = vertices[0] + (vertices[2] - vertices[0]) * fillStart;
|
||||
progressEnd = vertices[0] + (vertices[2] - vertices[0]) * fillEnd;
|
||||
progressStart = l + (r - l) * fillStart;
|
||||
progressEnd = l + (r - l) * fillEnd;
|
||||
|
||||
vertices[0] = progressStart;
|
||||
vertices[2] = progressEnd;
|
||||
vertices[4] = progressStart;
|
||||
vertices[6] = progressEnd;
|
||||
l = progressStart;
|
||||
r = progressEnd;
|
||||
|
||||
uvs[0] = quadUV[0] + (quadUV[2] - quadUV[0]) * fillStart;
|
||||
uvs[1] = quadUV[1];
|
||||
@@ -551,13 +527,11 @@ var fillQuadGeneratorBar = {
|
||||
uvs[7] = quadUV[7];
|
||||
break;
|
||||
case FillType.VERTICAL:
|
||||
progressStart = vertices[1] + (vertices[5] - vertices[1]) * fillStart;
|
||||
progressEnd = vertices[1] + (vertices[5] - vertices[1]) * fillEnd;
|
||||
progressStart = b + (t - b) * fillStart;
|
||||
progressEnd = b + (t - b) * fillEnd;
|
||||
|
||||
vertices[1] = progressStart;
|
||||
vertices[3] = progressStart;
|
||||
vertices[5] = progressEnd;
|
||||
vertices[7] = progressEnd;
|
||||
b = progressStart;
|
||||
t = progressEnd;
|
||||
|
||||
uvs[0] = quadUV[0];
|
||||
uvs[1] = quadUV[1] + (quadUV[5] - quadUV[1]) * fillStart;
|
||||
@@ -572,6 +546,28 @@ var fillQuadGeneratorBar = {
|
||||
cc.error('Unrecognized fill type in bar fill');
|
||||
break;
|
||||
}
|
||||
|
||||
//build vertices
|
||||
if (webgl) {
|
||||
vertices[0] = l * wt.a + b * wt.c + wt.tx;
|
||||
vertices[1] = l * wt.b + b * wt.d + wt.ty;
|
||||
vertices[2] = r * wt.a + b * wt.c + wt.tx;
|
||||
vertices[3] = r * wt.b + b * wt.d + wt.ty;
|
||||
vertices[4] = l * wt.a + t * wt.c + wt.tx;
|
||||
vertices[5] = l * wt.b + t * wt.d + wt.ty;
|
||||
vertices[6] = r * wt.a + t * wt.c + wt.tx;
|
||||
vertices[7] = r * wt.b + t * wt.d + wt.ty;
|
||||
} else{
|
||||
vertices[0] = l;
|
||||
vertices[1] = b;
|
||||
vertices[2] = r;
|
||||
vertices[3] = b;
|
||||
vertices[4] = l;
|
||||
vertices[5] = t;
|
||||
vertices[6] = r;
|
||||
vertices[7] = t;
|
||||
}
|
||||
|
||||
sprite._vertCount = 4;
|
||||
|
||||
cornerId[0] = 0;
|
||||
@@ -603,8 +599,7 @@ var fillQuadGeneratorRadial = {
|
||||
while (fillStart < 0.0) fillStart += 1.0;
|
||||
var cx = fillCenter.x * contentSize.width,
|
||||
cy = fillCenter.y * contentSize.height;
|
||||
var center = cc.v2( webgl ? cx * wt.a + cy * wt.c + wt.tx : cx,
|
||||
webgl ? cx * wt.b + cy * wt.d + wt.ty : cy);
|
||||
var center = cc.v2( cx, cy);
|
||||
|
||||
fillStart *= Math.PI * 2;
|
||||
fillRange *= Math.PI * 2;
|
||||
@@ -697,7 +692,7 @@ var fillQuadGeneratorRadial = {
|
||||
}
|
||||
//all in
|
||||
if(fillRange >= Math.PI * 2) {
|
||||
this._generateTriangle(offset, center, this._vertPos[triangle[0]], this._vertPos[triangle[1]]);
|
||||
this._generateTriangle(wt, offset, center, this._vertPos[triangle[0]], this._vertPos[triangle[1]]);
|
||||
offset += 6;
|
||||
count += 3;
|
||||
continue;
|
||||
@@ -715,10 +710,10 @@ var fillQuadGeneratorRadial = {
|
||||
} else if (startAngle >= fillStart) {
|
||||
if(endAngle >= fillEnd) {
|
||||
//startAngle to fillEnd
|
||||
this._generateTriangle(offset, center, this._vertPos[triangle[0]], this._intersectPoint_2[triangleIndex]);
|
||||
this._generateTriangle(wt, offset, center, this._vertPos[triangle[0]], this._intersectPoint_2[triangleIndex]);
|
||||
} else {
|
||||
//startAngle to endAngle
|
||||
this._generateTriangle(offset, center, this._vertPos[triangle[0]], this._vertPos[triangle[1]]);
|
||||
this._generateTriangle(wt, offset, center, this._vertPos[triangle[0]], this._vertPos[triangle[1]]);
|
||||
}
|
||||
offset += 6;
|
||||
count += 3;
|
||||
@@ -728,12 +723,12 @@ var fillQuadGeneratorRadial = {
|
||||
//all out
|
||||
} else if(endAngle <= fillEnd) {
|
||||
//fillStart to endAngle
|
||||
this._generateTriangle(offset, center, this._intersectPoint_1[triangleIndex], this._vertPos[triangle[1]]);
|
||||
this._generateTriangle(wt, offset, center, this._intersectPoint_1[triangleIndex], this._vertPos[triangle[1]]);
|
||||
offset += 6;
|
||||
count += 3;
|
||||
} else {
|
||||
//fillStart to fillEnd
|
||||
this._generateTriangle(offset, center, this._intersectPoint_1[triangleIndex], this._intersectPoint_2[triangleIndex]);
|
||||
this._generateTriangle(wt, offset, center, this._intersectPoint_1[triangleIndex], this._intersectPoint_2[triangleIndex]);
|
||||
offset += 6;
|
||||
count += 3;
|
||||
}
|
||||
@@ -751,7 +746,7 @@ var fillQuadGeneratorRadial = {
|
||||
cornerId[3] = 6;
|
||||
},
|
||||
|
||||
_generateTriangle: function(offset, vert0, vert1, vert2) {
|
||||
_generateTriangle: function(wt, offset, vert0, vert1, vert2) {
|
||||
var rawVerts = this.rawVerts;
|
||||
var rawUvs = this.rawUvs;
|
||||
var vertices = this.outVerts;
|
||||
@@ -763,12 +758,22 @@ var fillQuadGeneratorRadial = {
|
||||
// tl: 0, 1
|
||||
// bl: 2, 3
|
||||
// tr: 4, 5
|
||||
vertices[offset] = vert0.x;
|
||||
vertices[offset+1] = vert0.y;
|
||||
vertices[offset+2] = vert1.x;
|
||||
vertices[offset+3] = vert1.y;
|
||||
vertices[offset+4] = vert2.x;
|
||||
vertices[offset+5] = vert2.y;
|
||||
if(webgl) {
|
||||
vertices[offset] = vert0.x * wt.a + vert0.y * wt.c + wt.tx;
|
||||
vertices[offset+1] = vert0.x * wt.b + vert0.y * wt.d + wt.ty;
|
||||
vertices[offset+2] = vert1.x * wt.a + vert1.y * wt.c + wt.tx;
|
||||
vertices[offset+3] = vert1.x * wt.b + vert1.y * wt.d + wt.ty;
|
||||
vertices[offset+4] = vert2.x * wt.a + vert2.y * wt.c + wt.tx;
|
||||
vertices[offset+5] = vert2.x * wt.b + vert2.y * wt.d + wt.ty;
|
||||
|
||||
} else {
|
||||
vertices[offset] = vert0.x;
|
||||
vertices[offset+1] = vert0.y;
|
||||
vertices[offset+2] = vert1.x;
|
||||
vertices[offset+3] = vert1.y;
|
||||
vertices[offset+4] = vert2.x;
|
||||
vertices[offset+5] = vert2.y;
|
||||
}
|
||||
|
||||
progressX = (vert0.x - v0x) / (v1x - v0x);
|
||||
progressY = (vert0.y - v0y) / (v1y - v0y);
|
||||
@@ -879,18 +884,10 @@ var fillQuadGeneratorRadial = {
|
||||
x3 = contentSize.width;
|
||||
y3 = contentSize.height;
|
||||
|
||||
if (webgl) {
|
||||
this._vertices[0].x = x0 * wt.a + y0 * wt.c + wt.tx;
|
||||
this._vertices[0].y = x0 * wt.b + y0 * wt.d + wt.ty;
|
||||
this._vertices[1].x = x3 * wt.a + y3 * wt.c + wt.tx;
|
||||
this._vertices[1].y = x3 * wt.b + y3 * wt.d + wt.ty;
|
||||
}
|
||||
else {
|
||||
this._vertices[0].x = x0;
|
||||
this._vertices[0].y = y0;
|
||||
this._vertices[1].x = x3;
|
||||
this._vertices[1].y = y3;
|
||||
}
|
||||
this._vertices[0].x = x0;
|
||||
this._vertices[0].y = y0;
|
||||
this._vertices[1].x = x3;
|
||||
this._vertices[1].y = y3;
|
||||
},
|
||||
|
||||
_calculateUVs : function (spriteFrame) {
|
||||
|
||||
@@ -103,13 +103,14 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset){
|
||||
|
||||
if (node._distortionOffset && this._shaderProgram === Scale9Sprite.WebGLRenderCmd._distortionProgram) {
|
||||
this._shaderProgram.setUniformLocationWith2f(
|
||||
Scale9Sprite.WebGLRenderCmd._distortionOffset,
|
||||
node._distortionOffset.x, node._distortionOffset.y
|
||||
Scale9Sprite.WebGLRenderCmd._distortionOffset,
|
||||
node._distortionOffset.x, node._distortionOffset.y
|
||||
);
|
||||
this._shaderProgram.setUniformLocationWith2f(
|
||||
Scale9Sprite.WebGLRenderCmd._distortionTiling,
|
||||
node._distortionTiling.x, node._distortionTiling.y
|
||||
Scale9Sprite.WebGLRenderCmd._distortionTiling,
|
||||
node._distortionTiling.x, node._distortionTiling.y
|
||||
);
|
||||
cc.renderer._breakBatch();
|
||||
}
|
||||
|
||||
// Color & z
|
||||
|
||||
@@ -96,7 +96,6 @@ var Texture2D = cc.Class(/** @lends cc.Texture2D# */{
|
||||
this._isGray = false;
|
||||
}
|
||||
else if (cc._renderType === game.RENDER_TYPE_WEBGL) {
|
||||
this._hasPremultipliedAlpha = false;
|
||||
this._pixelFormat = Texture2D.defaultPixelFormat;
|
||||
this._hasPremultipliedAlpha = false;
|
||||
this._hasMipmaps = false;
|
||||
|
||||
@@ -85,7 +85,7 @@ var textureCache = /** @lends cc.textureCache# */{
|
||||
return this._textures[textureKeyName];
|
||||
},
|
||||
|
||||
/**
|
||||
/*
|
||||
* @method getKeyByTexture
|
||||
* @param {Image} texture
|
||||
* @return {String|Null}
|
||||
|
||||
@@ -1610,7 +1610,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
* treating the returned/received node point as anchor relative.
|
||||
* !#zh
|
||||
* 将一个点转换到世界空间坐标系。结果以 Vec2 为单位。<br/>
|
||||
* 返回值将基于节点坐标。
|
||||
* 返回值将基于世界坐标。
|
||||
* @method convertToWorldSpaceAR
|
||||
* @param {Vec2} nodePoint
|
||||
* @return {Vec2}
|
||||
|
||||
@@ -73,6 +73,14 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{
|
||||
return this._renderCmd.isPlaying();
|
||||
},
|
||||
|
||||
duration: function () {
|
||||
return this._renderCmd.duration();
|
||||
},
|
||||
|
||||
currentTime: function() {
|
||||
return this._renderCmd.currentTime();
|
||||
},
|
||||
|
||||
createDomElementIfNeeded: function () {
|
||||
if (!this._renderCmd._video) {
|
||||
this._renderCmd.createDom();
|
||||
@@ -501,6 +509,7 @@ _ccsg.VideoPlayer.EventType = {
|
||||
};
|
||||
|
||||
proto.isPlaying = function () {
|
||||
var video = this._video;
|
||||
if(_ccsg.VideoPlayer._polyfill.autoplayAfterOperation && this._playing){
|
||||
setTimeout(function(){
|
||||
video.play();
|
||||
@@ -509,4 +518,18 @@ _ccsg.VideoPlayer.EventType = {
|
||||
return this._playing;
|
||||
};
|
||||
|
||||
proto.duration = function () {
|
||||
var video = this._video;
|
||||
if(!video) return -1;
|
||||
|
||||
return video.duration;
|
||||
};
|
||||
|
||||
proto.currentTime = function () {
|
||||
var video = this._video;
|
||||
if(!video) return -1;
|
||||
|
||||
return video.currentTime;
|
||||
};
|
||||
|
||||
})(_ccsg.VideoPlayer._polyfill);
|
||||
|
||||
+49
-6
@@ -1,11 +1,12 @@
|
||||
var js = cc.js;
|
||||
|
||||
// Label
|
||||
if (cc.Label) {
|
||||
js.obsolete(cc.Label.prototype, 'cc.Label.file', 'font', true);
|
||||
}
|
||||
if (CC_DEV && typeof eruda === 'undefined') {
|
||||
|
||||
if (CC_DEV) {
|
||||
var js = cc.js;
|
||||
|
||||
// Label
|
||||
if (cc.Label) {
|
||||
js.obsolete(cc.Label.prototype, 'cc.Label.file', 'font', true);
|
||||
}
|
||||
|
||||
var INFO = cc._LogInfos.deprecated;
|
||||
|
||||
@@ -210,6 +211,11 @@ if (CC_DEV) {
|
||||
return cc.js.array.copy;
|
||||
});
|
||||
|
||||
js.get(cc, 'PI', function () {
|
||||
cc.warn(INFO, 'cc.PI', 'Math.PI');
|
||||
return Math.PI;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the Tile set information for the layer.
|
||||
* @memberof cc.TiledLayer
|
||||
@@ -612,4 +618,41 @@ if (CC_DEV) {
|
||||
'*etTimeScale': 'timeScale',
|
||||
});
|
||||
}
|
||||
|
||||
// SCENE
|
||||
|
||||
var ERR = '"%s" is not defined in the Scene, it is only defined in normal nodes.';
|
||||
Object.defineProperties(cc.Scene.prototype, {
|
||||
active: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'active');
|
||||
return true;
|
||||
},
|
||||
set: function () {
|
||||
cc.error(ERR, 'active');
|
||||
}
|
||||
},
|
||||
activeInHierarchy: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'activeInHierarchy');
|
||||
return true;
|
||||
},
|
||||
},
|
||||
getComponent: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'getComponent');
|
||||
return function () {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
},
|
||||
addComponent: {
|
||||
get: function () {
|
||||
cc.error(ERR, 'addComponent');
|
||||
return function () {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ if (ENABLE_GL_STATE_CACHE) {
|
||||
|
||||
var _currBuffers = {};
|
||||
|
||||
// IE 10 WebGLRenderingContext does not exist
|
||||
if (!window.WebGLRenderingContext) return;
|
||||
|
||||
WebGLRenderingContext.prototype.glBindBuffer = WebGLRenderingContext.prototype.bindBuffer;
|
||||
WebGLRenderingContext.prototype.bindBuffer = function (target, buffer) {
|
||||
if (_currBuffers[target] !== buffer) {
|
||||
|
||||
@@ -326,7 +326,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
* Tile set information for the layer
|
||||
* @return {cc.TMXTilesetInfo}
|
||||
*/
|
||||
getTileset:function () {
|
||||
getTileSet:function () {
|
||||
return this.tileset;
|
||||
},
|
||||
|
||||
@@ -334,7 +334,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
* Tile set information for the layer
|
||||
* @param {cc.TMXTilesetInfo} Var
|
||||
*/
|
||||
setTileset:function (Var) {
|
||||
setTileSet:function (Var) {
|
||||
this.tileset = Var;
|
||||
},
|
||||
|
||||
@@ -439,7 +439,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
return tile;
|
||||
}
|
||||
|
||||
var z = Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width;
|
||||
var z = Math.floor(x) + Math.floor(y) * this._layerSize.width;
|
||||
tile = this._spriteTiles[z];
|
||||
// tile not created yet. create it
|
||||
if (!tile) {
|
||||
@@ -482,7 +482,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
return null;
|
||||
}
|
||||
|
||||
var idx = Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width;
|
||||
var idx = Math.floor(x) + Math.floor(y) * this._layerSize.width;
|
||||
// Bits on the far end of the 32-bit global tile ID are used for tile flags
|
||||
var tile = this.tiles[idx];
|
||||
|
||||
|
||||
@@ -46,14 +46,17 @@ proto.constructor = _ccsg.TMXLayer.CanvasRenderCmd;
|
||||
|
||||
proto.visit = function (parentCmd) {
|
||||
var node = this._node, renderer = cc.renderer;
|
||||
|
||||
parentCmd = parentCmd || this.getParentRenderCmd();
|
||||
if (parentCmd) {
|
||||
this._curLevel = parentCmd._curLevel + 1;
|
||||
}
|
||||
this._propagateFlagsDown(parentCmd);
|
||||
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
|
||||
parentCmd = parentCmd || this.getParentRenderCmd();
|
||||
if (parentCmd)
|
||||
this._curLevel = parentCmd._curLevel + 1;
|
||||
|
||||
if (isNaN(node._customZ)) {
|
||||
node._vertexZ = renderer.assignedZ;
|
||||
renderer.assignedZ += renderer.assignedZStep;
|
||||
@@ -62,7 +65,7 @@ proto.visit = function (parentCmd) {
|
||||
this._syncStatus(parentCmd);
|
||||
|
||||
// Visit children
|
||||
var children = node._children, child, cmd,
|
||||
var children = node._children, child,
|
||||
spTiles = node._spriteTiles,
|
||||
i, len = children.length;
|
||||
if (len > 0) {
|
||||
@@ -71,8 +74,7 @@ proto.visit = function (parentCmd) {
|
||||
for (i = 0; i < len; i++) {
|
||||
child = children[i];
|
||||
if (child._localZOrder < 0) {
|
||||
cmd = child._renderCmd;
|
||||
cmd.visit(this);
|
||||
child._renderCmd.visit(this);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
@@ -87,7 +89,7 @@ proto.visit = function (parentCmd) {
|
||||
child._vertexZ = renderer.assignedZ;
|
||||
renderer.assignedZ += renderer.assignedZStep;
|
||||
}
|
||||
child._renderCmd.updateStatus(this, true);
|
||||
child._renderCmd.updateStatus();
|
||||
continue;
|
||||
}
|
||||
child._renderCmd.visit(this);
|
||||
|
||||
@@ -32,10 +32,15 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @property {Array} properties - Properties from the group. They can be added using tilemap editors
|
||||
* Properties from the group. They can be added using tilemap editors.
|
||||
* @property properties
|
||||
* @type {Array}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @property {String} groupName - Name of the group
|
||||
* Name of the group
|
||||
* @property groupName
|
||||
* @type {String}
|
||||
*/
|
||||
cc.TMXObjectGroup = cc._Class.extend(/** @lends cc.TMXObjectGroup# */{
|
||||
properties: null,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,7 @@
|
||||
* cc.pool 是一个单例对象,用作为对象缓存池。<br/>
|
||||
* 它可以帮助您提高游戏性能,适用于优化对象的反复创建和销毁<br/>
|
||||
* @class pool
|
||||
* @deprecated !#en Please use cc.NodePool instead !#zh 请使用 cc.NodePool 代替
|
||||
*/
|
||||
cc.pool = /** @lends cc.pool# */{
|
||||
_pool: {},
|
||||
|
||||
@@ -128,7 +128,7 @@ var SkeletonData = cc.Class({
|
||||
// -------------------------------------------------
|
||||
|
||||
/**
|
||||
* @property {Texture2D} textures
|
||||
* @property {cc.Texture2D} textures
|
||||
*/
|
||||
textures: {
|
||||
default: [],
|
||||
|
||||
+4
-3
@@ -205,6 +205,7 @@ cc.Node.prototype.runAction = function (action) {
|
||||
action.release();
|
||||
action._retained = false;
|
||||
}
|
||||
return action;
|
||||
};
|
||||
|
||||
function getSGTarget (target) {
|
||||
@@ -347,19 +348,19 @@ var actionUpdate = {
|
||||
'JumpTo': syncPositionUpdate,
|
||||
'JumpBy': syncPositionUpdate,
|
||||
'Place': syncPositionUpdate,
|
||||
'CardinalSplineTo': syncPositionUpdate,
|
||||
'RotateTo': syncRotationUpdate,
|
||||
'RotateBy': syncRotationUpdate,
|
||||
'ScaleTo': syncScaleUpdate,
|
||||
'ScaleBy': syncScaleUpdate,
|
||||
'RemoveSelf': syncRemoveSelfUpdate,
|
||||
'SkewTo': syncSkewUpdate,
|
||||
'SkewBy': syncSkewUpdate,
|
||||
'Blink': syncOpacityUpdate,
|
||||
'FadeIn': syncOpacityUpdate,
|
||||
'FadeOut': syncOpacityUpdate,
|
||||
'FadeTo': syncOpacityUpdate,
|
||||
'TintTo': syncColorUpdate,
|
||||
'TintBy': syncColorUpdate
|
||||
'TintBy': syncColorUpdate,
|
||||
'BezierBy': syncPositionUpdate
|
||||
};
|
||||
|
||||
for (var key in actionUpdate) {
|
||||
|
||||
+9
-3
@@ -25,6 +25,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var AutoReleaseUtils = require('../cocos2d/core/load-pipeline/auto-release-utils');
|
||||
|
||||
// cc.director
|
||||
cc.js.mixin(cc.director, {
|
||||
/**
|
||||
@@ -122,8 +124,7 @@ cc.js.mixin(cc.director, {
|
||||
var persistNodes = game._persistRootNodes;
|
||||
|
||||
if (scene instanceof cc.Scene) {
|
||||
// ensure scene initialized
|
||||
scene._load();
|
||||
scene._load(); // ensure scene initialized
|
||||
}
|
||||
|
||||
// detach persist nodes
|
||||
@@ -134,8 +135,13 @@ cc.js.mixin(cc.director, {
|
||||
game._ignoreRemovePersistNode = null;
|
||||
}
|
||||
|
||||
// unload scene
|
||||
var oldScene = this._scene;
|
||||
|
||||
// auto release assets
|
||||
var autoReleaseAssets = oldScene && oldScene.autoReleaseAssets && oldScene.dependAssets;
|
||||
AutoReleaseUtils.autoRelease(cc.loader, autoReleaseAssets, scene.dependAssets);
|
||||
|
||||
// unload scene
|
||||
if (cc.isValid(oldScene)) {
|
||||
oldScene.destroy();
|
||||
}
|
||||
|
||||
+8
-2
@@ -259,6 +259,12 @@ cc.js.mixin(cc.game, {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
cc.EventTarget.call(cc.game);
|
||||
cc.js.addon(cc.game, cc.EventTarget.prototype);
|
||||
cc.js.addon(cc.game, cc.EventTarget.prototype);
|
||||
|
||||
cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function () {
|
||||
cc.game.emit(cc.game.EVENT_HIDE, cc.game);
|
||||
});
|
||||
cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () {
|
||||
cc.game.emit(cc.game.EVENT_SHOW, cc.game);
|
||||
});
|
||||
@@ -32,6 +32,7 @@ require('../cocos2d/core/assets/CCAsset');
|
||||
// cc.SpriteFrameAnimation = cc.Animation;
|
||||
|
||||
// cc.textureCache.cacheImage
|
||||
|
||||
cc.textureCache._textures = {};
|
||||
cc.textureCache.cacheImage = function (key, texture) {
|
||||
if (texture instanceof cc.Texture2D) {
|
||||
@@ -56,8 +57,10 @@ var prototype = cc.Texture2D.prototype;
|
||||
prototype.isLoaded = function () {
|
||||
return true;
|
||||
};
|
||||
prototype.releaseTexture = prototype.releaseGLTexture;
|
||||
prototype.getPixelWidth = prototype.getPixelsWide;
|
||||
prototype.getPixelHeight = prototype.getPixelsHigh;
|
||||
prototype.description = prototype.getDescription;
|
||||
cc.js.get(prototype, 'pixelWidth', prototype.getPixelWidth);
|
||||
cc.js.get(prototype, 'pixelHeight', prototype.getPixelHeight);
|
||||
|
||||
@@ -73,7 +76,6 @@ prototype.textureLoaded = function () {
|
||||
return this.getTexture() !== null;
|
||||
};
|
||||
|
||||
// cc.SpriteFrame
|
||||
prototype._ctor = function (filename, rect, rotated, offset, originalSize) {
|
||||
this._name = '';
|
||||
if (filename !== undefined) {
|
||||
|
||||
+1
-1
@@ -11,6 +11,7 @@
|
||||
"test": "gulp test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "1.5.2",
|
||||
"browserify": "13.0.0",
|
||||
"chalk": "1.1.0",
|
||||
"del": "1.2.0",
|
||||
@@ -27,7 +28,6 @@
|
||||
"gulp-rename": "1.2.2",
|
||||
"gulp-shell": "0.4.1",
|
||||
"gulp-size": "2.1.0",
|
||||
"async": "1.5.2",
|
||||
"gulp-sourcemaps": "1.5.2",
|
||||
"gulp-uglify": "1.5.3",
|
||||
"gulp-util": "3.0.6",
|
||||
|
||||
Reference in New Issue
Block a user