mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Merge 1.6
# Conflicts: # cocos2d/core/CCDirector.js # cocos2d/core/components/CCSprite.js
This commit is contained in:
@@ -214,7 +214,7 @@ cc.ActionInterval = cc.FiniteTimeAction.extend({
|
||||
* !#zh
|
||||
* 改变一个动作的速度,使它的执行使用更长的时间(speed > 1)<br/>
|
||||
* 或更少(speed < 1)可以有效得模拟“慢动作”或“快进”的效果。
|
||||
* @param speed
|
||||
* @param {Number} speed
|
||||
* @returns {Action}
|
||||
*/
|
||||
speed: function(speed){
|
||||
@@ -252,7 +252,7 @@ cc.ActionInterval = cc.FiniteTimeAction.extend({
|
||||
* To repeat an action forever use the CCRepeatForever action.
|
||||
* !#zh 重复动作可以按一定次数重复一个动作,使用 RepeatForever 动作来永远重复一个动作。
|
||||
* @method repeat
|
||||
* @param times
|
||||
* @param {Number} times
|
||||
* @returns {ActionInterval}
|
||||
*/
|
||||
repeat: function(times){
|
||||
@@ -306,6 +306,7 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
_actions:null,
|
||||
_split:null,
|
||||
_last:0,
|
||||
_reversed:false,
|
||||
|
||||
ctor:function (tempArray) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
@@ -379,7 +380,7 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
// action[0]
|
||||
new_t = (locSplit !== 0) ? dt / locSplit : 1;
|
||||
|
||||
if (found === 0 && locLast === 1) {
|
||||
if (found === 0 && locLast === 1 && this._reversed) {
|
||||
// Reverse mode ?
|
||||
// XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode"
|
||||
// since it will require a hack to know if an action is on reverse mode or not.
|
||||
@@ -398,7 +399,7 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
locActions[0].update(1);
|
||||
locActions[0].stop();
|
||||
}
|
||||
if (!locLast) {
|
||||
if (locLast === 0) {
|
||||
// switching to action 1. stop action 0.
|
||||
locActions[0].update(1);
|
||||
locActions[0].stop();
|
||||
@@ -410,7 +411,7 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
if (locLast === found && actionFound.isDone())
|
||||
return;
|
||||
|
||||
// Last action found and it is done
|
||||
// Last action not found
|
||||
if (locLast !== found)
|
||||
actionFound.startWithTarget(this.target);
|
||||
|
||||
@@ -423,6 +424,7 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
var action = cc.Sequence._actionOneTwo(this._actions[1].reverse(), this._actions[0].reverse());
|
||||
this._cloneDecoration(action);
|
||||
this._reverseEaseList(action);
|
||||
action._reversed = true;
|
||||
return action;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -195,7 +195,7 @@ Audio.State = {
|
||||
} catch (error) {}
|
||||
this._element.pause();
|
||||
// remove touchPlayList
|
||||
for (var i=0; i<touchPlayList; i++) {
|
||||
for (var i=0; i<touchPlayList.length; i++) {
|
||||
if (touchPlayList[i].instance === this) {
|
||||
touchPlayList.splice(i, 1);
|
||||
break;
|
||||
|
||||
@@ -95,7 +95,6 @@ var audioEngine = {
|
||||
* @param {Number} volume - Volume size.
|
||||
* @return {Number} audioId
|
||||
* @example
|
||||
* //example
|
||||
* var audioID = cc.audioEngine.play(path, false, 0.5);
|
||||
*/
|
||||
play: function (filePath, loop, volume/*, profile*/) {
|
||||
@@ -127,7 +126,6 @@ var audioEngine = {
|
||||
* @param {Number} audioID - audio id.
|
||||
* @param {Boolean} loop - Whether cycle.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.setLoop(id, true);
|
||||
*/
|
||||
setLoop: function (audioID, loop) {
|
||||
@@ -144,7 +142,6 @@ var audioEngine = {
|
||||
* @param {Number} audioID - audio id.
|
||||
* @return {Boolean} Whether cycle.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.isLoop(id);
|
||||
*/
|
||||
isLoop: function (audioID) {
|
||||
@@ -158,10 +155,9 @@ var audioEngine = {
|
||||
* !#en Set the volume of audio.
|
||||
* !#zh 设置音量(0.0 ~ 1.0)。
|
||||
* @method setVolume
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Number} volume Volume must be in 0.0~1.0 .
|
||||
* @param {Number} audioID - audio id.
|
||||
* @param {Number} volume - Volume must be in 0.0~1.0 .
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.setVolume(id, 0.5);
|
||||
*/
|
||||
setVolume: function (audioID, volume) {
|
||||
@@ -181,10 +177,9 @@ var audioEngine = {
|
||||
* !#en The volume of the music max value is 1.0,the min value is 0.0 .
|
||||
* !#zh 获取音量(0.0 ~ 1.0)。
|
||||
* @method getVolume
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Number} audioID - audio id.
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* //example
|
||||
* var volume = cc.audioEngine.getVolume(id);
|
||||
*/
|
||||
getVolume: function (audioID) {
|
||||
@@ -198,11 +193,10 @@ var audioEngine = {
|
||||
* !#en Set current time
|
||||
* !#zh 设置当前的音频时间。
|
||||
* @method setCurrentTime
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Number} sec current time.
|
||||
* @param {Number} audioID - audio id.
|
||||
* @param {Number} sec - current time.
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.setCurrentTime(id, 2);
|
||||
*/
|
||||
setCurrentTime: function (audioID, sec) {
|
||||
@@ -224,10 +218,9 @@ var audioEngine = {
|
||||
* !#en Get current time
|
||||
* !#zh 获取当前的音频播放时间。
|
||||
* @method getCurrentTime
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Number} audioID - audio id.
|
||||
* @return {Number} audio current time.
|
||||
* @example
|
||||
* //example
|
||||
* var time = cc.audioEngine.getCurrentTime(id);
|
||||
*/
|
||||
getCurrentTime: function (audioID) {
|
||||
@@ -241,10 +234,9 @@ var audioEngine = {
|
||||
* !#en Get audio duration
|
||||
* !#zh 获取音频总时长。
|
||||
* @method getDuration
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Number} audioID - audio id.
|
||||
* @return {Number} audio duration.
|
||||
* @example
|
||||
* //example
|
||||
* var time = cc.audioEngine.getDuration(id);
|
||||
*/
|
||||
getDuration: function (audioID) {
|
||||
@@ -258,10 +250,9 @@ var audioEngine = {
|
||||
* !#en Get audio state
|
||||
* !#zh 获取音频状态。
|
||||
* @method getState
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Number} audioID - audio id.
|
||||
* @return {audioEngine.AudioState} audio duration.
|
||||
* @example
|
||||
* //example
|
||||
* var state = cc.audioEngine.getState(id);
|
||||
*/
|
||||
getState: function (audioID) {
|
||||
@@ -275,10 +266,9 @@ var audioEngine = {
|
||||
* !#en Set Audio finish callback
|
||||
* !#zh 设置一个音频结束后的回调
|
||||
* @method setFinishCallback
|
||||
* @param {Number} audioID audio id.
|
||||
* @param {Function} callback loaded callback.
|
||||
* @param {Number} audioID - audio id.
|
||||
* @param {Function} callback - loaded callback.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.setFinishCallback(id, function () {});
|
||||
*/
|
||||
setFinishCallback: function (audioID, callback) {
|
||||
@@ -297,7 +287,6 @@ var audioEngine = {
|
||||
* @method pause
|
||||
* @param {Number} audioID - The return value of function play.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.pause(audioID);
|
||||
*/
|
||||
pause: function (audioID) {
|
||||
@@ -314,7 +303,6 @@ var audioEngine = {
|
||||
* !#zh 暂停现在正在播放的所有音频。
|
||||
* @method pauseAll
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.pauseAll();
|
||||
*/
|
||||
pauseAll: function () {
|
||||
@@ -352,7 +340,6 @@ var audioEngine = {
|
||||
* !#zh 恢复播放所有之前暂停的所有音频。
|
||||
* @method resumeAll
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.resumeAll();
|
||||
*/
|
||||
resumeAll: function () {
|
||||
@@ -370,7 +357,6 @@ var audioEngine = {
|
||||
* @method stop
|
||||
* @param {Number} audioID - The return value of function play.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.stop(audioID);
|
||||
*/
|
||||
stop: function (audioID) {
|
||||
@@ -387,7 +373,6 @@ var audioEngine = {
|
||||
* !#zh 停止正在播放的所有音频。
|
||||
* @method stopAll
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.stopAll();
|
||||
*/
|
||||
stopAll: function () {
|
||||
@@ -404,9 +389,8 @@ var audioEngine = {
|
||||
* !#en Set up an audio can generate a few examples.
|
||||
* !#zh 设置一个音频可以设置几个实例
|
||||
* @method setMaxAudioInstance
|
||||
* @param {Number} num a number of instances to be created from within an audio
|
||||
* @param {Number} num - a number of instances to be created from within an audio
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.setMaxAudioInstance(20);
|
||||
*/
|
||||
setMaxAudioInstance: function (num) {
|
||||
@@ -417,9 +401,8 @@ var audioEngine = {
|
||||
* !#en Getting audio can produce several examples.
|
||||
* !#zh 获取一个音频可以设置几个实例
|
||||
* @method getMaxAudioInstance
|
||||
* @return {Number} a number of instances to be created from within an audio
|
||||
* @return {Number} a - number of instances to be created from within an audio
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.getMaxAudioInstance();
|
||||
*/
|
||||
getMaxAudioInstance: function () {
|
||||
@@ -432,7 +415,6 @@ var audioEngine = {
|
||||
* @method uncache
|
||||
* @param {String} filePath
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.uncache(filePath);
|
||||
*/
|
||||
uncache: function (filePath) {
|
||||
@@ -453,7 +435,6 @@ var audioEngine = {
|
||||
* !#zh 卸载所有音频。
|
||||
* @method uncacheAll
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.uncacheAll();
|
||||
*/
|
||||
uncacheAll: function () {
|
||||
@@ -473,15 +454,14 @@ var audioEngine = {
|
||||
/**
|
||||
* !#en Preload audio file.
|
||||
* !#zh 预加载一个音频
|
||||
* @param filePath The file path of an audio.
|
||||
* @param callback The callback of an audio.
|
||||
* @method preload
|
||||
* @param {String} filePath - The file path of an audio.
|
||||
* @param {Function} [callback] - The callback of an audio.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.preload(path);
|
||||
*/
|
||||
preload: function (filePath, callback) {
|
||||
cc.loader.load(filePath, function (error) {
|
||||
cc.loader.load(filePath, callback && function (error) {
|
||||
if (!error) {
|
||||
callback();
|
||||
}
|
||||
@@ -489,12 +469,11 @@ var audioEngine = {
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Set a size, the unit is KB,Over this size is directly resolved into DOM nodes
|
||||
* !#zh 设置一个以kb为单位的尺寸,大于这个尺寸的音频在加载的时候会强制使用 dom 方式加载
|
||||
* @param kb The file path of an audio.
|
||||
* !#en Set a size, the unit is KB. Over this size is directly resolved into DOM nodes.
|
||||
* !#zh 设置一个以 KB 为单位的尺寸,大于这个尺寸的音频在加载的时候会强制使用 dom 方式加载
|
||||
* @method setMaxWebAudioSize
|
||||
* @param {Number} kb - The file path of an audio.
|
||||
* @example
|
||||
* //example
|
||||
* cc.audioEngine.setMaxWebAudioSize(300);
|
||||
*/
|
||||
// Because webAudio takes up too much memory,So allow users to manually choose
|
||||
|
||||
@@ -1264,6 +1264,13 @@ cc.js.addon(cc.Director.prototype, EventTarget.prototype);
|
||||
* cc.log("Projection changed.");
|
||||
* });
|
||||
*/
|
||||
/**
|
||||
* !#en The event projection changed of cc.Director.
|
||||
* !#zh cc.Director 投影变化的事件。
|
||||
* @property {String} EVENT_PROJECTION_CHANGED
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed";
|
||||
|
||||
/**
|
||||
@@ -1273,6 +1280,13 @@ cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed";
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {Vec2} event.detail - The loading scene name
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered before loading a new scene.
|
||||
* !#zh 加载新场景之前所触发的事件。
|
||||
* @property {String} EVENT_BEFORE_SCENE_LOADING
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading";
|
||||
|
||||
/*
|
||||
@@ -1282,6 +1296,13 @@ cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading";
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {Vec2} event.detail - New scene which will be launched
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered before launching a new scene.
|
||||
* !#zh 运行新场景之前所触发的事件。
|
||||
* @property {String} EVENT_BEFORE_SCENE_LAUNCH
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch";
|
||||
|
||||
/**
|
||||
@@ -1291,6 +1312,13 @@ cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch";
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {Vec2} event.detail - New scene which is launched
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered after launching a new scene.
|
||||
* !#zh 运行新场景之后所触发的事件。
|
||||
* @property {String} EVENT_AFTER_SCENE_LAUNCH
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_AFTER_SCENE_LAUNCH = "director_after_scene_launch";
|
||||
|
||||
/**
|
||||
@@ -1299,6 +1327,13 @@ cc.Director.EVENT_AFTER_SCENE_LAUNCH = "director_after_scene_launch";
|
||||
* @event cc.Director.EVENT_BEFORE_UPDATE
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered at the beginning of every frame.
|
||||
* !#zh 每个帧的开始时所触发的事件。
|
||||
* @property {String} EVENT_BEFORE_UPDATE
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_BEFORE_UPDATE = "director_before_update";
|
||||
|
||||
/**
|
||||
@@ -1307,6 +1342,13 @@ cc.Director.EVENT_BEFORE_UPDATE = "director_before_update";
|
||||
* @event cc.Director.EVENT_AFTER_UPDATE
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered after engine and components update logic.
|
||||
* !#zh 将在引擎和组件 “update” 逻辑之后所触发的事件。
|
||||
* @property {String} EVENT_AFTER_UPDATE
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_AFTER_UPDATE = "director_after_update";
|
||||
|
||||
/**
|
||||
@@ -1315,16 +1357,34 @@ cc.Director.EVENT_AFTER_UPDATE = "director_after_update";
|
||||
* @event cc.Director.EVENT_BEFORE_VISIT
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered before visiting the rendering scene graph.
|
||||
* !#zh 访问渲染场景树之前所触发的事件。
|
||||
* @property {String} EVENT_BEFORE_VISIT
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_BEFORE_VISIT = "director_before_visit";
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* The event which will be triggered after visiting the rendering scene graph,
|
||||
* the render queue is ready but not rendered at this point.
|
||||
* !#zh 访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一时刻还没有呈现在画布上。
|
||||
* !#zh
|
||||
* 访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一时刻还没有呈现在画布上。
|
||||
* @event cc.Director.EVENT_AFTER_VISIT
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
/**
|
||||
* !#en
|
||||
* The event which will be triggered after visiting the rendering scene graph,
|
||||
* the render queue is ready but not rendered at this point.
|
||||
* !#zh
|
||||
* 访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一时刻还没有呈现在画布上。
|
||||
* @property {String} EVENT_AFTER_VISIT
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_AFTER_VISIT = "director_after_visit";
|
||||
|
||||
/**
|
||||
@@ -1333,11 +1393,19 @@ cc.Director.EVENT_AFTER_VISIT = "director_after_visit";
|
||||
* @event cc.Director.EVENT_AFTER_DRAW
|
||||
* @param {Event.EventCustom} event
|
||||
*/
|
||||
/**
|
||||
* !#en The event which will be triggered after the rendering process.
|
||||
* !#zh 渲染过程之后所触发的事件。
|
||||
* @property {String} EVENT_AFTER_DRAW
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.EVENT_AFTER_DRAW = "director_after_draw";
|
||||
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
||||
cc.DisplayLinkDirector = cc.Director.extend(/** @lends cc.Director# */{
|
||||
invalid: false,
|
||||
|
||||
@@ -1485,30 +1553,39 @@ cc.Director._getInstance = function () {
|
||||
cc.defaultFPS = 60;
|
||||
|
||||
//Possible OpenGL projections used by director
|
||||
|
||||
/**
|
||||
* Constant for 2D projection (orthogonal projection)
|
||||
* @constant
|
||||
* @type {Number}
|
||||
* @property {Number} PROJECTION_2D
|
||||
* @default 0
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.PROJECTION_2D = 0;
|
||||
|
||||
/**
|
||||
* Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500.
|
||||
* @constant
|
||||
* @type {Number}
|
||||
* @property {Number} PROJECTION_3D
|
||||
* @default 1
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.PROJECTION_3D = 1;
|
||||
|
||||
/**
|
||||
* Constant for custom projection, if cc.Director's projection set to it, it calls "updateProjection" on the projection delegate.
|
||||
* @constant
|
||||
* @type {Number}
|
||||
* @property {Number} PROJECTION_CUSTOM
|
||||
* @default 3
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.PROJECTION_CUSTOM = 3;
|
||||
|
||||
/**
|
||||
* Constant for default projection of cc.Director, default projection is 2D projection
|
||||
* @constant
|
||||
* @type {Number}
|
||||
* @property {Number} PROJECTION_DEFAULT
|
||||
* @default cc.Director.PROJECTION_2D
|
||||
* @readonly
|
||||
* @static
|
||||
*/
|
||||
cc.Director.PROJECTION_DEFAULT = cc.Director.PROJECTION_2D;
|
||||
|
||||
@@ -295,10 +295,16 @@ var game = {
|
||||
*/
|
||||
restart: function () {
|
||||
cc.director.once(cc.Director.EVENT_AFTER_DRAW, function () {
|
||||
for (var id in game._persistRootNodes) {
|
||||
game.removePersistRootNode(game._persistRootNodes[id]);
|
||||
}
|
||||
|
||||
// Clear scene
|
||||
cc.director.getScene().destroy();
|
||||
cc.Object._deferredDestroy();
|
||||
|
||||
cc.director.purgeDirector();
|
||||
|
||||
// Clean up audio
|
||||
if (cc.audioEngine) {
|
||||
cc.audioEngine.uncacheAll();
|
||||
@@ -558,15 +564,13 @@ var game = {
|
||||
|
||||
callback = function () {
|
||||
if (!self._paused) {
|
||||
self._intervalId = window.requestAnimFrame(callback);
|
||||
if (frameRate === 30) {
|
||||
if (skip = !skip) {
|
||||
self._intervalId = window.requestAnimFrame(callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
director.mainLoop();
|
||||
self._intervalId = window.requestAnimFrame(callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+15
-27
@@ -58,32 +58,28 @@ var EventType = cc.Enum({
|
||||
/**
|
||||
* !#en The event type for touch start event, you can use its value directly: 'touchstart'
|
||||
* !#zh 当手指触摸到屏幕时。
|
||||
* @property TOUCH_START
|
||||
* @type {String}
|
||||
* @property {String} TOUCH_START
|
||||
* @static
|
||||
*/
|
||||
TOUCH_START: 'touchstart',
|
||||
/**
|
||||
* !#en The event type for touch move event, you can use its value directly: 'touchmove'
|
||||
* !#zh 当手指在屏幕上目标节点区域内移动时。
|
||||
* @property TOUCH_MOVE
|
||||
* @type {String}
|
||||
* @property {String} TOUCH_MOVE
|
||||
* @static
|
||||
*/
|
||||
TOUCH_MOVE: 'touchmove',
|
||||
/**
|
||||
* !#en The event type for touch end event, you can use its value directly: 'touchend'
|
||||
* !#zh 当手指在目标节点区域内离开屏幕时。
|
||||
* @property TOUCH_END
|
||||
* @type {String}
|
||||
* @property {String} TOUCH_END
|
||||
* @static
|
||||
*/
|
||||
TOUCH_END: 'touchend',
|
||||
/**
|
||||
* !#en The event type for touch end event, you can use its value directly: 'touchcancel'
|
||||
* !#zh 当手指在目标节点区域外离开屏幕时。
|
||||
* @property TOUCH_CANCEL
|
||||
* @type {String}
|
||||
* @property {String} TOUCH_CANCEL
|
||||
* @static
|
||||
*/
|
||||
TOUCH_CANCEL: 'touchcancel',
|
||||
@@ -91,48 +87,42 @@ var EventType = cc.Enum({
|
||||
/**
|
||||
* !#en The event type for mouse down events, you can use its value directly: 'mousedown'
|
||||
* !#zh 当鼠标按下时触发一次。
|
||||
* @property MOUSE_DOWN
|
||||
* @type {String}
|
||||
* @property {String} MOUSE_DOWN
|
||||
* @static
|
||||
*/
|
||||
MOUSE_DOWN: 'mousedown',
|
||||
/**
|
||||
* !#en The event type for mouse move events, you can use its value directly: 'mousemove'
|
||||
* !#zh 当鼠标在目标节点在目标节点区域中移动时,不论是否按下。
|
||||
* @property MOUSE_MOVE
|
||||
* @type {String}
|
||||
* @property {String} MOUSE_MOVE
|
||||
* @static
|
||||
*/
|
||||
MOUSE_MOVE: 'mousemove',
|
||||
/**
|
||||
* !#en The event type for mouse enter target events, you can use its value directly: 'mouseenter'
|
||||
* !#zh 当鼠标移入目标节点区域时,不论是否按下。
|
||||
* @property MOUSE_ENTER
|
||||
* @type {String}
|
||||
* @property {String} MOUSE_ENTER
|
||||
* @static
|
||||
*/
|
||||
MOUSE_ENTER: 'mouseenter',
|
||||
/**
|
||||
* !#en The event type for mouse leave target events, you can use its value directly: 'mouseleave'
|
||||
* !#zh 当鼠标移出目标节点区域时,不论是否按下。
|
||||
* @property MOUSE_LEAVE
|
||||
* @type {String}
|
||||
* @property {String} MOUSE_LEAVE
|
||||
* @static
|
||||
*/
|
||||
MOUSE_LEAVE: 'mouseleave',
|
||||
/**
|
||||
* !#en The event type for mouse up events, you can use its value directly: 'mouseup'
|
||||
* !#zh 当鼠标从按下状态松开时触发一次。
|
||||
* @property MOUSE_UP
|
||||
* @type {String}
|
||||
* @property {String} MOUSE_UP
|
||||
* @static
|
||||
*/
|
||||
MOUSE_UP: 'mouseup',
|
||||
/**
|
||||
* !#en The event type for mouse wheel events, you can use its value directly: 'mousewheel'
|
||||
* !#zh 当鼠标滚轮滚动时。
|
||||
* @property MOUSE_WHEEL
|
||||
* @type {String}
|
||||
* @property {String} MOUSE_WHEEL
|
||||
* @static
|
||||
*/
|
||||
MOUSE_WHEEL: 'mousewheel',
|
||||
@@ -1315,14 +1305,12 @@ var Node = cc.Class({
|
||||
h = this.height;
|
||||
var rect = cc.rect(0, 0, w, h);
|
||||
|
||||
var trans;
|
||||
if (cc.Camera && cc.Camera.main) {
|
||||
trans = cc.Camera.main.getNodeToCameraTransform(this);
|
||||
var Camera = cc.Camera;
|
||||
if (Camera && Camera.main && Camera.main.containsNode(this)) {
|
||||
point = Camera.main.getCameraToWorldPoint(point);
|
||||
}
|
||||
else {
|
||||
trans = this.getNodeToWorldTransform();
|
||||
}
|
||||
|
||||
|
||||
var trans = this.getNodeToWorldTransform();
|
||||
cc._rectApplyAffineTransformIn(rect, trans);
|
||||
var left = point.x - rect.x,
|
||||
right = rect.x + rect.width - point.x,
|
||||
|
||||
@@ -246,6 +246,7 @@ let Camera = cc.Class({
|
||||
* Returns the matrix that transform the node's (local) space coordinates into the camera's space coordinates.
|
||||
* !#zh
|
||||
* 返回一个将节点坐标系转换到摄像机坐标系下的矩阵
|
||||
* @method getNodeToCameraTransform
|
||||
* @param {Node} node - the node which should transform
|
||||
* @return {AffineTransform}
|
||||
*/
|
||||
@@ -261,7 +262,8 @@ let Camera = cc.Class({
|
||||
* !#en
|
||||
* Conver a camera coordinates point to world coordinates.
|
||||
* !#zh
|
||||
* 讲一个摄像机坐标系下的点转换到世界坐标系下。
|
||||
* 将一个摄像机坐标系下的点转换到世界坐标系下。
|
||||
* @method getCameraToWorldPoint
|
||||
* @param {Node} point - the point which should transform
|
||||
* @return {Vec2}
|
||||
*/
|
||||
@@ -277,6 +279,7 @@ let Camera = cc.Class({
|
||||
* Check whether the node is in the camera.
|
||||
* !#zh
|
||||
* 检测节点是否被此摄像机影响
|
||||
* @method containsNode
|
||||
* @param {Node} node - the node which need to check
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
@@ -170,8 +170,11 @@ var Animation = cc.Class({
|
||||
|
||||
start: function () {
|
||||
if (!CC_EDITOR && this.playOnLoad && this._defaultClip) {
|
||||
var state = this.getAnimationState(this._defaultClip.name);
|
||||
this._animator.playState(state);
|
||||
var isPlaying = this._animator && this._animator.isPlaying;
|
||||
if (!isPlaying) {
|
||||
var state = this.getAnimationState(this._defaultClip.name);
|
||||
this._animator.playState(state);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -148,12 +148,16 @@ var HorizontalDirection = cc.Enum({
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* The Layout is a container component, use it to arrange child elements easily.
|
||||
* But after setting the Layout, the results need to be updated until the next frame,
|
||||
* The Layout is a container component, use it to arrange child elements easily.<br>
|
||||
* Note:<br>
|
||||
* 1.Scaling and rotation of child nodes are not considered.<br>
|
||||
* 2.After setting the Layout, the results need to be updated until the next frame,
|
||||
* unless you manually call {{#crossLink "Layout/updateLayout:method"}}{{/crossLink}}。
|
||||
* !#zh
|
||||
* Layout 组件相当于一个容器,能自动对它的所有子节点进行统一排版。
|
||||
* 但是对 Layout 设置后结果需要到下一帧才会更新,除非你设置完以后手动调用 {{#crossLink "Layout/updateLayout:method"}}{{/crossLink}}。
|
||||
* Layout 组件相当于一个容器,能自动对它的所有子节点进行统一排版。<br>
|
||||
* 注意:<br>
|
||||
* 1.不会考虑子节点的缩放和旋转。<br>
|
||||
* 2.对 Layout 设置后结果需要到下一帧才会更新,除非你设置完以后手动调用 {{#crossLink "Layout/updateLayout:method"}}{{/crossLink}}。
|
||||
* @class Layout
|
||||
* @extends Component
|
||||
*/
|
||||
|
||||
@@ -58,7 +58,7 @@ var RichText = cc.Class({
|
||||
name: 'cc.RichText',
|
||||
extends: cc._RendererUnderSG,
|
||||
|
||||
ctor: function() {
|
||||
ctor: function () {
|
||||
this._textArray = null;
|
||||
this._labelSegments = [];
|
||||
this._labelSegmentsCache = [];
|
||||
@@ -66,9 +66,10 @@ var RichText = cc.Class({
|
||||
|
||||
this._resetState();
|
||||
|
||||
if(CC_EDITOR) {
|
||||
if (CC_EDITOR) {
|
||||
this._updateRichTextStatus = debounce(this._updateRichText, 200);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this._updateRichTextStatus = this._updateRichText;
|
||||
}
|
||||
},
|
||||
@@ -105,7 +106,7 @@ var RichText = cc.Class({
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.horizontal_align',
|
||||
animatable: false,
|
||||
notify: function (oldValue) {
|
||||
if(this.horizontalAlign === oldValue) return;
|
||||
if (this.horizontalAlign === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
this._updateRichTextStatus();
|
||||
@@ -121,7 +122,7 @@ var RichText = cc.Class({
|
||||
default: 40,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.font_size',
|
||||
notify: function (oldValue) {
|
||||
if(this.fontSize === oldValue) return;
|
||||
if (this.fontSize === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
this._updateRichTextStatus();
|
||||
@@ -138,10 +139,10 @@ var RichText = cc.Class({
|
||||
type: cc.TTFFont,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.font',
|
||||
notify: function (oldValue) {
|
||||
if(this.font === oldValue) return;
|
||||
if (this.font === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
if(!CC_JSB && this.font) {
|
||||
if (!CC_JSB && this.font) {
|
||||
this._onTTFLoaded();
|
||||
}
|
||||
this._updateRichTextStatus();
|
||||
@@ -157,7 +158,7 @@ var RichText = cc.Class({
|
||||
default: 0,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.max_width',
|
||||
notify: function (oldValue) {
|
||||
if(this.maxWidth === oldValue) return;
|
||||
if (this.maxWidth === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
this._updateRichTextStatus();
|
||||
@@ -173,7 +174,7 @@ var RichText = cc.Class({
|
||||
default: 40,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.line_height',
|
||||
notify: function (oldValue) {
|
||||
if(this.lineHeight === oldValue) return;
|
||||
if (this.lineHeight === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
this._updateRichTextStatus();
|
||||
@@ -189,12 +190,32 @@ var RichText = cc.Class({
|
||||
default: null,
|
||||
type: cc.SpriteAtlas,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.image_atlas',
|
||||
notify: function(oldValue) {
|
||||
if(this.imageAtlas === oldValue) return;
|
||||
notify: function (oldValue) {
|
||||
if (this.imageAtlas === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
this._updateRichTextStatus();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Once checked, the RichText will block all input events (mouse and touch) within
|
||||
* the bounding box of the node, preventing the input from penetrating into the underlying node.
|
||||
* !#zh
|
||||
* 选中此选项后,RichText 将阻止节点边界框中的所有输入事件(鼠标和触摸),从而防止输入事件穿透到底层节点。
|
||||
* @property {Boolean} handleTouchEvent
|
||||
* @default true
|
||||
*/
|
||||
handleTouchEvent: {
|
||||
default: true,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.richtext.handleTouchEvent',
|
||||
notify: function (oldValue) {
|
||||
if (this.handleTouchEvent === oldValue) return;
|
||||
if (this.enabledInHierarchy) {
|
||||
this.handleTouchEvent ? this._addEventListeners() : this._removeEventListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -205,11 +226,23 @@ var RichText = cc.Class({
|
||||
|
||||
onEnable: function () {
|
||||
this._super();
|
||||
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
if (this.handleTouchEvent) {
|
||||
this._addEventListeners();
|
||||
}
|
||||
},
|
||||
|
||||
onDisable: function () {
|
||||
this._super();
|
||||
if (this.handleTouchEvent) {
|
||||
this._removeEventListeners();
|
||||
}
|
||||
},
|
||||
|
||||
_addEventListeners: function () {
|
||||
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
},
|
||||
|
||||
_removeEventListeners: function () {
|
||||
this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
},
|
||||
|
||||
@@ -228,24 +261,24 @@ var RichText = cc.Class({
|
||||
return sgNode;
|
||||
},
|
||||
|
||||
_updateLabelSegmentTextAttributes: function() {
|
||||
this._labelSegments.forEach(function(item) {
|
||||
_updateLabelSegmentTextAttributes: function () {
|
||||
this._labelSegments.forEach(function (item) {
|
||||
this._applyTextAttribute(item);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
_initSgNode: function () {
|
||||
this._updateRichText();
|
||||
if(!CC_JSB) {
|
||||
if (!CC_JSB) {
|
||||
this._onTTFLoaded();
|
||||
}
|
||||
},
|
||||
|
||||
_createFontLabel: function (string) {
|
||||
return _ccsg.Label.pool.get(string, this.font, null, this.fontSize);
|
||||
return _ccsg.Label.pool.get(string, this.font, null, this.fontSize);
|
||||
},
|
||||
|
||||
_getFontRawUrl: function() {
|
||||
_getFontRawUrl: function () {
|
||||
var isAsset = this.font instanceof cc.TTFFont;
|
||||
var fntRawUrl = isAsset ? this.font.rawUrl : '';
|
||||
return fntRawUrl;
|
||||
@@ -253,7 +286,7 @@ var RichText = cc.Class({
|
||||
|
||||
_onTTFLoaded: function () {
|
||||
var rawUrl = this._getFontRawUrl();
|
||||
if(!rawUrl) return;
|
||||
if (!rawUrl) return;
|
||||
|
||||
var self = this;
|
||||
|
||||
@@ -269,10 +302,11 @@ var RichText = cc.Class({
|
||||
var self = this;
|
||||
var func = function (string) {
|
||||
var label;
|
||||
if(self._labelSegmentsCache.length === 0) {
|
||||
if (self._labelSegmentsCache.length === 0) {
|
||||
label = self._createFontLabel(string);
|
||||
self._labelSegmentsCache.push(label);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label = self._labelSegmentsCache[0];
|
||||
label.setString(string);
|
||||
}
|
||||
@@ -281,41 +315,40 @@ var RichText = cc.Class({
|
||||
var labelSize = label.getContentSize();
|
||||
return labelSize.width;
|
||||
};
|
||||
if(string) {
|
||||
if (string) {
|
||||
return func(string);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return func;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
_onTouchEnded: function (event) {
|
||||
if(!this.enabledInHierarchy) return;
|
||||
|
||||
var components = this.node.getComponents(cc.Component);
|
||||
|
||||
for (var i = 0; i < this._labelSegments.length; ++i ) {
|
||||
for (var i = 0; i < this._labelSegments.length; ++i) {
|
||||
var labelSegment = this._labelSegments[i];
|
||||
var clickHandler = labelSegment._clickHandler;
|
||||
if (clickHandler && this._containsTouchLocation(labelSegment, event.touch.getLocation())) {
|
||||
components.forEach(function(component) {
|
||||
if(component.enabledInHierarchy && component[clickHandler]) {
|
||||
components.forEach(function (component) {
|
||||
if (component.enabledInHierarchy && component[clickHandler]) {
|
||||
component[clickHandler](event);
|
||||
}
|
||||
});
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_containsTouchLocation:function (label, point) {
|
||||
_containsTouchLocation: function (label, point) {
|
||||
var myRect = label.getBoundingBoxToWorld();
|
||||
|
||||
return cc.rectContainsPoint(myRect, point);
|
||||
},
|
||||
|
||||
_resetState: function () {
|
||||
var sgNode = this._sgNode;
|
||||
if(sgNode) {
|
||||
if (sgNode) {
|
||||
sgNode.removeAllChildren();
|
||||
}
|
||||
|
||||
@@ -329,11 +362,12 @@ var RichText = cc.Class({
|
||||
this._layoutDirty = true;
|
||||
},
|
||||
|
||||
_addLabelSegment: function(stringToken, styleIndex) {
|
||||
_addLabelSegment: function (stringToken, styleIndex) {
|
||||
var labelSegment;
|
||||
if(this._labelSegmentsCache.length === 0) {
|
||||
if (this._labelSegmentsCache.length === 0) {
|
||||
labelSegment = this._createFontLabel(stringToken);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
labelSegment = this._labelSegmentsCache.pop();
|
||||
labelSegment.setString(stringToken);
|
||||
}
|
||||
@@ -350,7 +384,7 @@ var RichText = cc.Class({
|
||||
//in Web platform, the extra pixels will be trimed.
|
||||
//so we need to set the overflow to clamp in JSB
|
||||
//FIXME: label in jsb should be refactored to keep the behavior the same as web platform.
|
||||
if(CC_JSB) {
|
||||
if (CC_JSB) {
|
||||
labelSegment.setOverflow(1);
|
||||
var size = labelSegment.getContentSize();
|
||||
labelSegment.enableWrap(false);
|
||||
@@ -369,17 +403,18 @@ var RichText = cc.Class({
|
||||
var checkStartIndex = 0;
|
||||
while (this._lineOffsetX <= this.maxWidth) {
|
||||
var checkEndIndex = this._getFirstWordLen(labelString,
|
||||
checkStartIndex,
|
||||
labelString.length);
|
||||
checkStartIndex,
|
||||
labelString.length);
|
||||
var checkString = labelString.substr(checkStartIndex, checkEndIndex);
|
||||
var checkStringWidth = this._measureText(styleIndex, checkString);
|
||||
|
||||
if(this._lineOffsetX + checkStringWidth <= this.maxWidth) {
|
||||
if (this._lineOffsetX + checkStringWidth <= this.maxWidth) {
|
||||
this._lineOffsetX += checkStringWidth;
|
||||
checkStartIndex += checkEndIndex;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
if(checkStartIndex > 0) {
|
||||
if (checkStartIndex > 0) {
|
||||
var remainingString = labelString.substr(0, checkStartIndex);
|
||||
|
||||
this._addLabelSegment(remainingString, styleIndex);
|
||||
@@ -392,33 +427,34 @@ var RichText = cc.Class({
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fragmentWidth > this.maxWidth) {
|
||||
if (fragmentWidth > this.maxWidth) {
|
||||
var fragments = cc.TextUtils.fragmentText(labelString,
|
||||
fragmentWidth,
|
||||
this.maxWidth,
|
||||
this._measureText(styleIndex));
|
||||
for(var k = 0; k < fragments.length; ++k) {
|
||||
fragmentWidth,
|
||||
this.maxWidth,
|
||||
this._measureText(styleIndex));
|
||||
for (var k = 0; k < fragments.length; ++k) {
|
||||
var splitString = fragments[k];
|
||||
|
||||
labelSegment = this._addLabelSegment(splitString, styleIndex);
|
||||
labelSegment = this._addLabelSegment(splitString, styleIndex);
|
||||
|
||||
var labelSize = labelSegment.getContentSize();
|
||||
|
||||
this._lineOffsetX += labelSize.width;
|
||||
|
||||
if(fragments.length > 1 && k < fragments.length - 1) {
|
||||
if (fragments.length > 1 && k < fragments.length - 1) {
|
||||
this._updateLineInfo();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this._lineOffsetX += fragmentWidth;
|
||||
|
||||
this._addLabelSegment(labelString, styleIndex);
|
||||
}
|
||||
},
|
||||
|
||||
_isLastComponentCR: function(stringToken) {
|
||||
return stringToken.length -1 === stringToken.lastIndexOf("\n");
|
||||
_isLastComponentCR: function (stringToken) {
|
||||
return stringToken.length - 1 === stringToken.lastIndexOf("\n");
|
||||
},
|
||||
|
||||
_updateLineInfo: function () {
|
||||
@@ -428,40 +464,43 @@ var RichText = cc.Class({
|
||||
},
|
||||
|
||||
_needsUpdateTextLayout: function (newTextArray) {
|
||||
if(this._layoutDirty || !this._textArray || !newTextArray) {
|
||||
if (this._layoutDirty || !this._textArray || !newTextArray) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(this._textArray.length !== newTextArray.length) {
|
||||
if (this._textArray.length !== newTextArray.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(var i = 0; i < this._textArray.length; ++i) {
|
||||
for (var i = 0; i < this._textArray.length; ++i) {
|
||||
var oldItem = this._textArray[i];
|
||||
var newItem = newTextArray[i];
|
||||
if(oldItem.text != newItem.text) {
|
||||
if (oldItem.text != newItem.text) {
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (oldItem.style) {
|
||||
if (newItem.style) {
|
||||
if(oldItem.style.size !== newItem.style.size
|
||||
|| oldItem.style.italic !== newItem.style.italic
|
||||
|| oldItem.style.isImage !== newItem.style.isImage) {
|
||||
if (oldItem.style.size !== newItem.style.size
|
||||
|| oldItem.style.italic !== newItem.style.italic
|
||||
|| oldItem.style.isImage !== newItem.style.isImage) {
|
||||
return true;
|
||||
}
|
||||
if(oldItem.style.isImage === newItem.style.isImage) {
|
||||
if(oldItem.style.src !== newItem.style.src) {
|
||||
if (oldItem.style.isImage === newItem.style.isImage) {
|
||||
if (oldItem.style.src !== newItem.style.src) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(oldItem.style.size || oldItem.style.italic || oldItem.style.isImage) {
|
||||
}
|
||||
else {
|
||||
if (oldItem.style.size || oldItem.style.italic || oldItem.style.isImage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (newItem.style) {
|
||||
if(newItem.style.size || newItem.style.italic || newItem.style.isImage) {
|
||||
if (newItem.style.size || newItem.style.italic || newItem.style.isImage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -473,9 +512,10 @@ var RichText = cc.Class({
|
||||
|
||||
_onSpriteFrameLoaded: function (event, spriteFrame) {
|
||||
var newSpriteFrame;
|
||||
if(spriteFrame) {
|
||||
if (spriteFrame) {
|
||||
newSpriteFrame = spriteFrame;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
newSpriteFrame = event.target;
|
||||
}
|
||||
var sprite = newSpriteFrame.__sprite;
|
||||
@@ -483,10 +523,11 @@ var RichText = cc.Class({
|
||||
},
|
||||
|
||||
_applySpriteFrame: function (spriteFrame) {
|
||||
if(spriteFrame) {
|
||||
if(spriteFrame.textureLoaded()) {
|
||||
if (spriteFrame) {
|
||||
if (spriteFrame.textureLoaded()) {
|
||||
this._onSpriteFrameLoaded(null, spriteFrame);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
spriteFrame.once('load', this._onSpriteFrameLoaded, this);
|
||||
spriteFrame.ensureLoadTexture();
|
||||
}
|
||||
@@ -496,7 +537,7 @@ var RichText = cc.Class({
|
||||
_addRichTextImageElement: function (richTextElement) {
|
||||
var spriteFrameName = richTextElement.style.src;
|
||||
var spriteFrame = this.imageAtlas.getSpriteFrame(spriteFrameName);
|
||||
if(spriteFrame) {
|
||||
if (spriteFrame) {
|
||||
var sprite = new cc.Scale9Sprite();
|
||||
sprite.setAnchorPoint(0, 0);
|
||||
spriteFrame.__sprite = sprite;
|
||||
@@ -511,27 +552,29 @@ var RichText = cc.Class({
|
||||
var expectHeight = richTextElement.style.imageHeight;
|
||||
|
||||
//follow the original rule, expectHeight must less then lineHeight
|
||||
if(expectHeight > 0 && expectHeight < this.lineHeight ) {
|
||||
if (expectHeight > 0 && expectHeight < this.lineHeight) {
|
||||
scaleFactor = expectHeight / spriteHeight;
|
||||
spriteWidth = spriteWidth * scaleFactor;
|
||||
spriteHeight = spriteHeight * scaleFactor;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
scaleFactor = this.lineHeight / spriteHeight;
|
||||
spriteWidth = spriteWidth * scaleFactor;
|
||||
spriteHeight = spriteHeight * scaleFactor;
|
||||
}
|
||||
|
||||
if(expectWidth > 0) spriteWidth = expectWidth;
|
||||
if (expectWidth > 0) spriteWidth = expectWidth;
|
||||
|
||||
if(this.maxWidth > 0) {
|
||||
if(this._lineOffsetX + spriteWidth > this.maxWidth) {
|
||||
if (this.maxWidth > 0) {
|
||||
if (this._lineOffsetX + spriteWidth > this.maxWidth) {
|
||||
this._updateLineInfo();
|
||||
}
|
||||
this._lineOffsetX += spriteWidth;
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this._lineOffsetX += spriteWidth;
|
||||
if(this._lineOffsetX > this._labelWidth) {
|
||||
if (this._lineOffsetX > this._labelWidth) {
|
||||
this._labelWidth = this._lineOffsetX;
|
||||
}
|
||||
}
|
||||
@@ -539,12 +582,13 @@ var RichText = cc.Class({
|
||||
sprite.setContentSize(spriteWidth, spriteHeight);
|
||||
sprite._lineCount = this._lineCount;
|
||||
|
||||
if(richTextElement.style.event) {
|
||||
if(richTextElement.style.event.click) {
|
||||
if (richTextElement.style.event) {
|
||||
if (richTextElement.style.event.click) {
|
||||
sprite._clickHandler = richTextElement.style.event.click;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
cc.warnID(4400);
|
||||
}
|
||||
},
|
||||
@@ -553,14 +597,13 @@ var RichText = cc.Class({
|
||||
if (!this.enabled) return;
|
||||
|
||||
var newTextArray = cc.htmlTextParser.parse(this.string);
|
||||
if(!this._needsUpdateTextLayout(newTextArray)) {
|
||||
if (!this._needsUpdateTextLayout(newTextArray)) {
|
||||
this._textArray = newTextArray;
|
||||
this._updateLabelSegmentTextAttributes();
|
||||
return;
|
||||
}
|
||||
|
||||
this._textArray = newTextArray;
|
||||
var sgNode = this._sgNode;
|
||||
this._resetState();
|
||||
|
||||
var lastEmptyLine = false;
|
||||
@@ -571,12 +614,12 @@ var RichText = cc.Class({
|
||||
var richTextElement = this._textArray[i];
|
||||
var text = richTextElement.text;
|
||||
//handle <br/> <img /> tag
|
||||
if(text === "") {
|
||||
if(richTextElement.style && richTextElement.style.newline) {
|
||||
if (text === "") {
|
||||
if (richTextElement.style && richTextElement.style.newline) {
|
||||
this._updateLineInfo();
|
||||
continue;
|
||||
}
|
||||
if(richTextElement.style && richTextElement.style.isImage && this.imageAtlas) {
|
||||
if (richTextElement.style && richTextElement.style.isImage && this.imageAtlas) {
|
||||
this._addRichTextImageElement(richTextElement);
|
||||
continue;
|
||||
}
|
||||
@@ -585,10 +628,10 @@ var RichText = cc.Class({
|
||||
|
||||
for (var j = 0; j < multilineTexts.length; ++j) {
|
||||
var labelString = multilineTexts[j];
|
||||
if(labelString === "") {
|
||||
if (labelString === "") {
|
||||
//for continues \n
|
||||
if(this._isLastComponentCR(text)
|
||||
&& j == multilineTexts.length - 1) {
|
||||
if (this._isLastComponentCR(text)
|
||||
&& j == multilineTexts.length - 1) {
|
||||
continue;
|
||||
}
|
||||
this._updateLineInfo();
|
||||
@@ -597,46 +640,49 @@ var RichText = cc.Class({
|
||||
}
|
||||
lastEmptyLine = false;
|
||||
|
||||
if(this.maxWidth > 0) {
|
||||
if (this.maxWidth > 0) {
|
||||
var labelWidth = this._measureText(i, labelString);
|
||||
this._updateRichTextWithMaxWidth(labelString, labelWidth, i);
|
||||
|
||||
if(multilineTexts.length > 1 && j < multilineTexts.length - 1) {
|
||||
if (multilineTexts.length > 1 && j < multilineTexts.length - 1) {
|
||||
this._updateLineInfo();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label = this._addLabelSegment(labelString, i);
|
||||
labelSize = label.getContentSize();
|
||||
|
||||
this._lineOffsetX += labelSize.width;
|
||||
if(this._lineOffsetX > this._labelWidth) {
|
||||
if (this._lineOffsetX > this._labelWidth) {
|
||||
this._labelWidth = this._lineOffsetX;
|
||||
}
|
||||
|
||||
if(multilineTexts.length > 1 && j < multilineTexts.length - 1) {
|
||||
if (multilineTexts.length > 1 && j < multilineTexts.length - 1) {
|
||||
this._updateLineInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!lastEmptyLine) {
|
||||
if (!lastEmptyLine) {
|
||||
this._linesWidth.push(this._lineOffsetX);
|
||||
}
|
||||
|
||||
if(this.maxWidth > 0) {
|
||||
if (this.maxWidth > 0) {
|
||||
this._labelWidth = this.maxWidth;
|
||||
}
|
||||
this._labelHeight =this._lineCount * this.lineHeight;
|
||||
this._labelHeight = this._lineCount * this.lineHeight;
|
||||
|
||||
sgNode._setContentSize(this._labelWidth, this._labelHeight);
|
||||
this.node.emit('size-changed');
|
||||
// trigger "size-changed" event
|
||||
this.node.setContentSize(this._labelWidth, this._labelHeight);
|
||||
// use _setContentSize because sgNode.setContentSize is banned.
|
||||
this._sgNode._setContentSize(this._labelWidth, this._labelHeight);
|
||||
|
||||
this._updateRichTextPosition();
|
||||
this._layoutDirty = false;
|
||||
},
|
||||
|
||||
|
||||
_getFirstWordLen: function(text, startIndex, textLen) {
|
||||
_getFirstWordLen: function (text, startIndex, textLen) {
|
||||
var character = text.charAt(startIndex);
|
||||
if (cc.TextUtils.isUnicodeCJK(character)
|
||||
|| cc.TextUtils.isUnicodeSpace(character)) {
|
||||
@@ -661,7 +707,7 @@ var RichText = cc.Class({
|
||||
var nextTokenX = 0;
|
||||
var nextLineIndex = 1;
|
||||
var totalLineCount = this._lineCount;
|
||||
for(var i = 0; i < this._labelSegments.length; ++i) {
|
||||
for (var i = 0; i < this._labelSegments.length; ++i) {
|
||||
var label = this._labelSegments[i];
|
||||
var lineCount = label._lineCount;
|
||||
if (lineCount > nextLineIndex) {
|
||||
@@ -670,17 +716,17 @@ var RichText = cc.Class({
|
||||
}
|
||||
var lineOffsetX = 0;
|
||||
switch (this.horizontalAlign) {
|
||||
case cc.TextAlignment.LEFT:
|
||||
lineOffsetX = 0;
|
||||
break;
|
||||
case cc.TextAlignment.CENTER:
|
||||
lineOffsetX = (this._labelWidth - this._linesWidth[lineCount - 1]) / 2;
|
||||
break;
|
||||
case cc.TextAlignment.RIGHT:
|
||||
lineOffsetX = this._labelWidth - this._linesWidth[lineCount - 1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case cc.TextAlignment.LEFT:
|
||||
lineOffsetX = 0;
|
||||
break;
|
||||
case cc.TextAlignment.CENTER:
|
||||
lineOffsetX = (this._labelWidth - this._linesWidth[lineCount - 1]) / 2;
|
||||
break;
|
||||
case cc.TextAlignment.RIGHT:
|
||||
lineOffsetX = this._labelWidth - this._linesWidth[lineCount - 1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
label.setPositionX(nextTokenX + lineOffsetX);
|
||||
|
||||
@@ -688,7 +734,7 @@ var RichText = cc.Class({
|
||||
|
||||
var positionY = (totalLineCount - lineCount) * this.lineHeight;
|
||||
|
||||
if(label instanceof cc.Scale9Sprite) {
|
||||
if (label instanceof cc.Scale9Sprite) {
|
||||
positionY += (this.lineHeight - label.getContentSize().height) / 2;
|
||||
}
|
||||
|
||||
@@ -705,13 +751,14 @@ var RichText = cc.Class({
|
||||
var colorValue = color.toUpperCase();
|
||||
if (cc.Color[colorValue]) {
|
||||
return cc.Color[colorValue];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return cc.hexToColor(color);
|
||||
}
|
||||
},
|
||||
|
||||
_applyTextAttribute: function (label) {
|
||||
if(label instanceof cc.Scale9Sprite) return;
|
||||
if (label instanceof cc.Scale9Sprite) return;
|
||||
|
||||
var index = label._styleIndex;
|
||||
label.setLineHeight(this.lineHeight);
|
||||
@@ -723,25 +770,29 @@ var RichText = cc.Class({
|
||||
}
|
||||
if (textStyle && textStyle.color) {
|
||||
label.setColor(this._convertLiteralColorValue(textStyle.color));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label.setColor(this.node.color);
|
||||
}
|
||||
|
||||
if (textStyle && textStyle.bold) {
|
||||
label.enableBold(true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label.enableBold(false);
|
||||
}
|
||||
|
||||
if (textStyle && textStyle.italic) {
|
||||
label.enableItalics(true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label.enableItalics(false);
|
||||
}
|
||||
|
||||
if (textStyle && textStyle.underline) {
|
||||
label.enableUnderline(true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label.enableUnderline(false);
|
||||
}
|
||||
|
||||
@@ -750,14 +801,16 @@ var RichText = cc.Class({
|
||||
label.setOutlineColor(this._convertLiteralColorValue(textStyle.outline.color));
|
||||
label.setOutlineWidth(textStyle.outline.width);
|
||||
label.setMargin(textStyle.outline.width);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label.setOutlined(false);
|
||||
label.setMargin(0);
|
||||
}
|
||||
|
||||
if (textStyle && textStyle.size) {
|
||||
label.setFontSize(textStyle.size);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
label.setFontSize(this.fontSize);
|
||||
}
|
||||
|
||||
@@ -776,6 +829,6 @@ var RichText = cc.Class({
|
||||
}
|
||||
this._resetState();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cc.RichText = module.exports = RichText;
|
||||
|
||||
@@ -47,6 +47,9 @@ var EventType = _ccsg.WebView.EventType;
|
||||
* @property {String} ERROR
|
||||
*/
|
||||
|
||||
//
|
||||
function emptyCallback () { }
|
||||
|
||||
/**
|
||||
* !#en cc.WebView is a component for display web pages in the game
|
||||
* !#zh WebView 组件,用于在游戏中显示网页
|
||||
@@ -124,12 +127,6 @@ var WebView = cc.Class({
|
||||
sgNode.createDomElementIfNeeded();
|
||||
}
|
||||
|
||||
if (!CC_EDITOR) {
|
||||
sgNode.setEventListener(EventType.LOADED, this._onWebViewLoaded.bind(this));
|
||||
sgNode.setEventListener(EventType.LOADING, this._onWebViewLoading.bind(this));
|
||||
sgNode.setEventListener(EventType.ERROR, this._onWebViewLoadError.bind(this));
|
||||
}
|
||||
|
||||
sgNode.loadURL(this._url);
|
||||
|
||||
if (CC_EDITOR && this._useOriginalSize) {
|
||||
@@ -140,6 +137,26 @@ var WebView = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
onEnable: function () {
|
||||
this._super();
|
||||
if (!CC_EDITOR) {
|
||||
var sgNode = this._sgNode;
|
||||
sgNode.setEventListener(EventType.LOADED, this._onWebViewLoaded.bind(this));
|
||||
sgNode.setEventListener(EventType.LOADING, this._onWebViewLoading.bind(this));
|
||||
sgNode.setEventListener(EventType.ERROR, this._onWebViewLoadError.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
onDisable: function () {
|
||||
this._super();
|
||||
if (!CC_EDITOR) {
|
||||
var sgNode = this._sgNode;
|
||||
sgNode.setEventListener(EventType.LOADED, emptyCallback);
|
||||
sgNode.setEventListener(EventType.LOADING, emptyCallback);
|
||||
sgNode.setEventListener(EventType.ERROR, emptyCallback);
|
||||
}
|
||||
},
|
||||
|
||||
_onWebViewLoaded: function () {
|
||||
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.LOADED);
|
||||
this.node.emit('loaded', this);
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
|
||||
// https://segmentfault.com/q/1010000002914610
|
||||
var SCROLLY = 40;
|
||||
var TIMER_NAME = 400;
|
||||
var LEFT_PADDING = 2;
|
||||
var DELAY_TIME = 400;
|
||||
var FOCUS_DELAY_UC = 400;
|
||||
var FOCUS_DELAY_FIREFOX = 0;
|
||||
var Utils = require('../platform/utils');
|
||||
|
||||
function adjustEditBoxPosition (editBox) {
|
||||
@@ -47,7 +49,7 @@ function adjustEditBoxPosition (editBox) {
|
||||
if (scrollOffset > 320) scrollOffset = 320;
|
||||
window.scrollTo(scrollOffset, scrollOffset);
|
||||
}
|
||||
}, TIMER_NAME);
|
||||
}, DELAY_TIME);
|
||||
}
|
||||
|
||||
var capitalize = function(string) {
|
||||
@@ -688,6 +690,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
tmpEdTxt.style.position = "absolute";
|
||||
tmpEdTxt.style.bottom = "0px";
|
||||
tmpEdTxt.style.left = LEFT_PADDING + "px";
|
||||
tmpEdTxt.style['-moz-appearance'] = 'textfield';
|
||||
tmpEdTxt.style.className = "cocosEditBox";
|
||||
|
||||
tmpEdTxt.addEventListener('input', function () {
|
||||
@@ -965,25 +968,33 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
this._updateLabelStringStyle();
|
||||
};
|
||||
|
||||
proto._beginEditing = function() {
|
||||
if (!this._editBox._alwaysOnTop) {
|
||||
if (this._edTxt.style.display === 'none') {
|
||||
this._edTxt.style.display = '';
|
||||
proto._beginEditing = function () {
|
||||
var self = this;
|
||||
if (!self._editBox._alwaysOnTop) {
|
||||
if (self._edTxt.style.display === 'none') {
|
||||
self._edTxt.style.display = '';
|
||||
|
||||
function startFocus () {
|
||||
self._edTxt.focus();
|
||||
}
|
||||
|
||||
if (cc.sys.browserType === cc.sys.BROWSER_TYPE_UC) {
|
||||
setTimeout(function () {
|
||||
this._edTxt.focus();
|
||||
}.bind(this), TIMER_NAME);
|
||||
} else {
|
||||
this._edTxt.focus();
|
||||
setTimeout(startFocus, FOCUS_DELAY_UC);
|
||||
}
|
||||
else if (cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX) {
|
||||
setTimeout(startFocus, FOCUS_DELAY_FIREFOX);
|
||||
}
|
||||
else {
|
||||
startFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cc.sys.isMobile && !this._editingMode) {
|
||||
if (cc.sys.isMobile && !self._editingMode) {
|
||||
// Pre adaptation and
|
||||
this._beginEditingOnMobile(this._editBox);
|
||||
self._beginEditingOnMobile(self._editBox);
|
||||
}
|
||||
this._editingMode = true;
|
||||
self._editingMode = true;
|
||||
};
|
||||
|
||||
proto._endEditing = function() {
|
||||
@@ -996,7 +1007,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
// Delay end editing adaptation to ensure virtual keyboard is disapeared
|
||||
setTimeout(function () {
|
||||
self._endEditingOnMobile();
|
||||
}, TIMER_NAME);
|
||||
}, DELAY_TIME);
|
||||
}
|
||||
this._editingMode = false;
|
||||
};
|
||||
|
||||
@@ -743,9 +743,9 @@ _p._expandFill = function () {
|
||||
if (path.complex) {
|
||||
var data = [];
|
||||
var start = offset*VERTS_FLOAT_LENGTH, end = buffer.vertsOffset*VERTS_FLOAT_LENGTH;
|
||||
for (var i = start; i < end; i+=VERTS_FLOAT_LENGTH) {
|
||||
data.push(buffer.vertsBuffer[i]);
|
||||
data.push(buffer.vertsBuffer[i+1]);
|
||||
for (var j = start; j < end; j+=VERTS_FLOAT_LENGTH) {
|
||||
data.push(buffer.vertsBuffer[j]);
|
||||
data.push(buffer.vertsBuffer[j+1]);
|
||||
}
|
||||
|
||||
var newIndices = Earcut(data, null, 2);
|
||||
|
||||
@@ -280,13 +280,14 @@ var ccclass = checkCtorArgument(function (ctor, name) {
|
||||
|
||||
// validate methods
|
||||
if (CC_DEV) {
|
||||
var methods = Object.getOwnPropertyNames(ctor.prototype);
|
||||
for (var i = 0; i < methods.length; ++i) {
|
||||
var methodName = methods[i];
|
||||
if (methodName !== 'constructor') {
|
||||
var func = ctor.prototype[methodName];
|
||||
var propNames = Object.getOwnPropertyNames(ctor.prototype);
|
||||
for (var i = 0; i < propNames.length; ++i) {
|
||||
var prop = propNames[i];
|
||||
if (prop !== 'constructor') {
|
||||
var desc = Object.getOwnPropertyDescriptor(ctor.prototype, prop);
|
||||
var func = desc && desc.value;
|
||||
if (typeof func === 'function') {
|
||||
Preprocess.doValidateMethodWithProps_DEV(func, methodName, JS.getClassName(ctor), ctor, base);
|
||||
Preprocess.doValidateMethodWithProps_DEV(func, prop, JS.getClassName(ctor), ctor, base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -743,43 +743,37 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
|
||||
var triangleBytesLen = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, trianglesBuffer = this._trianglesArrayBuffer;
|
||||
var locBuffer = this._buffer;
|
||||
var inset = (outline == false ? 0.5 : 0.0);
|
||||
|
||||
var va, vb, vc;
|
||||
for (i = 0; i < count - 2; i++) {
|
||||
v0 = cc.pSub(cc.v2(verts[0]), cc.pMult(extrude[0].offset, inset));
|
||||
v1 = cc.pSub(cc.v2(verts[i + 1]), cc.pMult(extrude[i + 1].offset, inset));
|
||||
v2 = cc.pSub(cc.v2(verts[i + 2]), cc.pMult(extrude[i + 2].offset, inset));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
{vertices: v1, colors: c4bFillColor, texCoords: __t(cc.v2())}, {vertices: v2, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
va = {vertices: verts[0], colors: c4bFillColor, texCoords: __t(cc.v2())};
|
||||
vb = {vertices: verts[i + 1], colors: c4bFillColor, texCoords: __t(cc.v2())};
|
||||
vc = {vertices: verts[i + 2], colors: c4bFillColor, texCoords: __t(cc.v2())};
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
}
|
||||
if (outline) {
|
||||
for (i = 0; i < count; i++) {
|
||||
var j = (i + 1) % count;
|
||||
v0 = cc.v2(verts[i]);
|
||||
v1 = cc.v2(verts[j]);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
var j = (i + 1) % count;
|
||||
v0 = cc.v2(verts[i]);
|
||||
v1 = cc.v2(verts[j]);
|
||||
var n0 = extrude[i].n;
|
||||
var offset0 = extrude[i].offset;
|
||||
var offset1 = extrude[j].offset;
|
||||
var inner0 = cc.pSub(v0, cc.pMult(offset0, borderWidth));
|
||||
var inner1 = cc.pSub(v1, cc.pMult(offset1, borderWidth));
|
||||
var outer0 = cc.pAdd(v0, cc.pMult(offset0, borderWidth));
|
||||
var outer1 = cc.pAdd(v1, cc.pMult(offset1, borderWidth));
|
||||
|
||||
var n0 = extrude[i].n;
|
||||
var offset0 = extrude[i].offset;
|
||||
var offset1 = extrude[j].offset;
|
||||
var inner0 = outline ? cc.pSub(v0, cc.pMult(offset0, borderWidth)) : cc.pSub(v0, cc.pMult(offset0, 0.5));
|
||||
var inner1 = outline ? cc.pSub(v1, cc.pMult(offset1, borderWidth)) : cc.pSub(v1, cc.pMult(offset1, 0.5));
|
||||
var outer0 = outline ? cc.pAdd(v0, cc.pMult(offset0, borderWidth)) : cc.pAdd(v0, cc.pMult(offset0, 0.5));
|
||||
var outer1 = outline ? cc.pAdd(v1, cc.pMult(offset1, borderWidth)) : cc.pAdd(v1, cc.pMult(offset1, 0.5));
|
||||
va = { vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) };
|
||||
vb = { vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) };
|
||||
vc = { vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0) };
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
|
||||
if (outline) {
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
|
||||
{vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
|
||||
{vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
} else {
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
{vertices: inner1, colors: c4bFillColor, texCoords: __t(cc.v2())}, {vertices: outer1, colors: c4bFillColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
{vertices: outer0, colors: c4bFillColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bFillColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
va = { vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) };
|
||||
vb = { vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0) };
|
||||
vc = { vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0) };
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
}
|
||||
}
|
||||
extrude = null;
|
||||
|
||||
@@ -45,7 +45,7 @@ var proto = _ccsg.TMXLayer.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.
|
||||
proto.constructor = _ccsg.TMXLayer.CanvasRenderCmd;
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var node = this._node, hasRotation = (node._rotationX || node._rotationY),
|
||||
var node = this._node,
|
||||
layerOrientation = node.layerOrientation,
|
||||
tiles = node.tiles,
|
||||
alpha = node._opacity / 255;
|
||||
@@ -80,7 +80,7 @@ proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
maxCol = cols, maxRow = rows;
|
||||
|
||||
if (cc.macro.ENABLE_TILEDMAP_CULLING) {
|
||||
if (!hasRotation && layerOrientation === Orientation.ORTHO) {
|
||||
if (layerOrientation === Orientation.ORTHO) {
|
||||
startCol = Math.floor(-(mapx - extw * a) / (maptw * a));
|
||||
startRow = Math.floor((mapy - exth * d + mapth * rows * d - winh) / (mapth * d));
|
||||
maxCol = Math.ceil((winw - mapx + extw * a) / (maptw * a));
|
||||
@@ -171,7 +171,7 @@ proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
right = left + tilew;
|
||||
top = bottom - tileh;
|
||||
// TMX_ORIENTATION_ISO trim
|
||||
if (!hasRotation && layerOrientation === Orientation.ISO) {
|
||||
if (layerOrientation === Orientation.ISO) {
|
||||
gb = -mapy + bottom*d;
|
||||
if (gb < -winh-h) {
|
||||
col += Math.floor((-winh - gb)*2/h) - 1;
|
||||
|
||||
@@ -70,7 +70,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
|
||||
// enable Depth Test
|
||||
cc.renderer.setDepthTest(true);
|
||||
|
||||
var node = this._node, hasRotation = (node._rotationX || node._rotationY),
|
||||
var node = this._node,
|
||||
layerOrientation = node.layerOrientation,
|
||||
tiles = node.tiles;
|
||||
|
||||
@@ -121,7 +121,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
|
||||
|
||||
if (enabledCulling) {
|
||||
if (this._cameraFlag > 0) {
|
||||
var tmpt = cc.affineTransformConcat(cc.Camera.main.viewMatrix, wt);
|
||||
var tmpt = cc.affineTransformConcat(wt, cc.Camera.main.viewMatrix);
|
||||
cullingA = tmpt.a;
|
||||
cullingD = tmpt.d;
|
||||
cullingMapx = ox * cullingA + oy * tmpt.c + tmpt.tx;
|
||||
@@ -130,7 +130,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
|
||||
cullingH = tileh * cullingD;
|
||||
}
|
||||
|
||||
if (!hasRotation && layerOrientation === Orientation.ORTHO) {
|
||||
if (layerOrientation === Orientation.ORTHO) {
|
||||
startCol = Math.floor(-(cullingMapx - extw * cullingA) / (maptw * cullingA));
|
||||
startRow = Math.floor((cullingMapy - exth * cullingD + mapth * rows * cullingD - winh) / (mapth * cullingD));
|
||||
maxCol = Math.ceil((winw - cullingMapx + extw * cullingA) / (maptw * cullingA));
|
||||
@@ -211,7 +211,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
|
||||
top = bottom + tileh;
|
||||
|
||||
// TMX_ORIENTATION_ISO trim
|
||||
if (enabledCulling && !hasRotation && layerOrientation === Orientation.ISO) {
|
||||
if (enabledCulling && layerOrientation === Orientation.ISO) {
|
||||
gb = cullingMapy + bottom*cullingD;
|
||||
if (gb > winh+cullingH) {
|
||||
col += Math.floor((gb-winh)*2/cullingH) - 1;
|
||||
|
||||
+63
-45
@@ -21,56 +21,74 @@ exports.getMacros = function (platform, isJSB, isDebugBuild) {
|
||||
|
||||
exports.getUglifyOptions = function (platform, isJSB, isDebugBuild) {
|
||||
var global_defs = exports.getMacros(platform, isJSB, isDebugBuild);
|
||||
if (!global_defs['CC_DEBUG']) {
|
||||
var releaseMode = !global_defs['CC_DEBUG'];
|
||||
|
||||
var optimizeForJSC = releaseMode && isJSB;
|
||||
if (optimizeForJSC) {
|
||||
return {
|
||||
output: {
|
||||
beautify: true, // really preserve_lines
|
||||
indent_level: 0, // reduce jsc file size
|
||||
},
|
||||
compress: {
|
||||
global_defs: global_defs,
|
||||
// keep_infinity: true
|
||||
sequences: false,
|
||||
keep_infinity: true, // reduce jsc file size
|
||||
typeofs: false,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
mangle: false,
|
||||
//preserveComments: 'all',
|
||||
output: {
|
||||
// http://lisperator.net/uglifyjs/codegen
|
||||
beautify: true,
|
||||
bracketize: true,
|
||||
},
|
||||
compress: {
|
||||
// https://github.com/mishoo/UglifyJS2#compressor-options
|
||||
global_defs: global_defs,
|
||||
sequences: false, // join consecutive statements with the “comma operator”
|
||||
properties: false, // optimize property access: a["foo"] → a.foo
|
||||
//dead_code: true, // discard unreachable code
|
||||
drop_debugger: false, // discard “debugger” statements
|
||||
unsafe: false, // some unsafe optimizations (see below)
|
||||
//conditionals: false, // optimize if-s and conditional expressions
|
||||
comparisons: false, // optimize comparisons
|
||||
//evaluate: true, // evaluate constant expressions
|
||||
booleans: false, // optimize boolean expressions
|
||||
typeofs: false, // Transforms typeof foo == "undefined" into foo === void 0. Note: recommend to set this value to false for IE10 and earlier versions due to known issues.
|
||||
loops: false, // optimize loops
|
||||
unused: false, // drop unused variables/functions
|
||||
hoist_funs: false, // hoist function declarations
|
||||
hoist_vars: false, // hoist variable declarations
|
||||
if_return: false, // optimize if-s followed by return/continue
|
||||
inline: false, // embed simple functions
|
||||
join_vars: false, // join var declarations
|
||||
cascade: false, // try to cascade `right` into `left` in sequences
|
||||
collapse_vars: false, // Collapse single-use non-constant variables - side effects permitting.
|
||||
reduce_vars: false, // Improve optimization on variables assigned with and used as constant values.
|
||||
//warnings: true,
|
||||
negate_iife: false,
|
||||
pure_getters: false,
|
||||
pure_funcs: null,
|
||||
drop_console: false,
|
||||
// expression: false, // Pass true to preserve completion values from terminal statements without return, e.g. in bookmarklets.
|
||||
keep_fargs: true,
|
||||
keep_fnames: true,
|
||||
// keep_infinity: false, // Pass true to prevent Infinity from being compressed into 1/0, which may cause performance issues on Chrome.
|
||||
side_effects: false // drop side-effect-free statements
|
||||
}
|
||||
};
|
||||
if (releaseMode) {
|
||||
return {
|
||||
compress: {
|
||||
global_defs: global_defs,
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
mangle: false,
|
||||
//preserveComments: 'all',
|
||||
output: {
|
||||
// http://lisperator.net/uglifyjs/codegen
|
||||
beautify: true,
|
||||
indent_level: 2,
|
||||
},
|
||||
compress: {
|
||||
// https://github.com/mishoo/UglifyJS2#compressor-options
|
||||
global_defs: global_defs,
|
||||
sequences: false, // join consecutive statements with the “comma operator”
|
||||
properties: false, // optimize property access: a["foo"] → a.foo
|
||||
//dead_code: true, // discard unreachable code
|
||||
drop_debugger: false, // discard “debugger” statements
|
||||
unsafe: false, // some unsafe optimizations (see below)
|
||||
//conditionals: false, // optimize if-s and conditional expressions
|
||||
comparisons: false, // optimize comparisons
|
||||
//evaluate: true, // evaluate constant expressions
|
||||
booleans: false, // optimize boolean expressions
|
||||
typeofs: false, // Transforms typeof foo == "undefined" into foo === void 0. Note: recommend to set this value to false for IE10 and earlier versions due to known issues.
|
||||
loops: false, // optimize loops
|
||||
unused: false, // drop unused variables/functions
|
||||
hoist_funs: false, // hoist function declarations
|
||||
hoist_vars: false, // hoist variable declarations
|
||||
if_return: false, // optimize if-s followed by return/continue
|
||||
inline: false, // embed simple functions
|
||||
join_vars: false, // join var declarations
|
||||
cascade: false, // try to cascade `right` into `left` in sequences
|
||||
collapse_vars: false, // Collapse single-use non-constant variables - side effects permitting.
|
||||
reduce_vars: false, // Improve optimization on variables assigned with and used as constant values.
|
||||
//warnings: true,
|
||||
negate_iife: false,
|
||||
pure_getters: false,
|
||||
pure_funcs: null,
|
||||
drop_console: false,
|
||||
// expression: false, // Pass true to preserve completion values from terminal statements without return, e.g. in bookmarklets.
|
||||
keep_fargs: true,
|
||||
keep_fnames: true,
|
||||
keep_infinity: true, // Pass true to prevent Infinity from being compressed into 1/0, which may cause performance issues on Chrome.
|
||||
side_effects: false // drop side-effect-free statements
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
+2
-2
@@ -174,8 +174,8 @@ if (cc.Image && cc.Image.setPNGPremultipliedAlphaEnabled) {
|
||||
}
|
||||
|
||||
// __errorHandler
|
||||
window.__errorHandler = function (filename, lineno, message) {
|
||||
};
|
||||
// window.__errorHandler = function (filename, lineno, message, stack) {
|
||||
// };
|
||||
|
||||
// global cleanup. Dangerous!!! please do not invoke this function, it's used internally by the restart process
|
||||
window.__cleanup = function () {
|
||||
|
||||
@@ -1358,3 +1358,35 @@ test('animation pause/resume should remove animation-actor from animation manage
|
||||
|
||||
strictEqual(manager._anims.array.length, 0, 'should remove animation from animation manager');
|
||||
});
|
||||
|
||||
|
||||
test('animation play on load', function () {
|
||||
var entity = new cc.Node();
|
||||
|
||||
var animation = entity.addComponent(cc.Animation);
|
||||
animation.playOnLoad = true;
|
||||
|
||||
var clip1 = new cc.AnimationClip();
|
||||
clip1._name = 'clip1';
|
||||
clip1._duration = 1;
|
||||
|
||||
var clip2 = new cc.AnimationClip();
|
||||
clip2._name = 'clip2';
|
||||
clip2._duration = 1;
|
||||
|
||||
|
||||
animation.addClip(clip1);
|
||||
animation.addClip(clip2);
|
||||
|
||||
animation._defaultClip = clip1;
|
||||
|
||||
animation.play('clip2');
|
||||
|
||||
entity.parent = cc.director.getScene();
|
||||
animation.start();
|
||||
|
||||
strictEqual(animation.getAnimationState('clip1').isPlaying, false, 'default clip should not be played if there is playing animation');
|
||||
strictEqual(animation.getAnimationState('clip2').isPlaying, true, 'should play the specified animation');
|
||||
|
||||
entity.parent = null;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user