mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #2337 from pandamicro/next
Remove cc.Pool, cc._Class, cc.configuration
This commit is contained in:
+5
-4
@@ -65,6 +65,7 @@ if (CC_DEBUG) {
|
||||
"1404": "cc.spriteFrameCache is removed, please use cc.loader to load and cache sprite frames of atlas format.",
|
||||
"1405": "The '%s' will be removed in v2.0, please use '%s' instead. \uD83D\uDE30",
|
||||
"1406": "'%s.%s' is removed", // removed
|
||||
"1407": "cc.pool is being removed from v2.0, you are getting cc.js.Pool instead",
|
||||
//Scheduler: 1500
|
||||
"1500": "cc.Scheduler#schedule: Callback already scheduled. Updating interval from:%s to %s", //scheduleCallbackForTarget
|
||||
"1501": "cc.Scheduler#scheduleCallbackForTarget(): callback_fn should be non-null.", //scheduleCallbackForTarget_2
|
||||
@@ -121,10 +122,10 @@ if (CC_DEBUG) {
|
||||
"1702": "cocos2d: Could not initialize cc.AtlasNode. Invalid Texture.", //_initWithTexture
|
||||
"1703": "The new text must be String", //TextAtlas.text
|
||||
//_checkEventListenerAvailable: 1800
|
||||
"1800": "cc._EventListenerKeyboard.checkAvailable(): Invalid EventListenerKeyboard!", //keyboard
|
||||
"1801": "cc._EventListenerTouchOneByOne.checkAvailable(): Invalid EventListenerTouchOneByOne!", //touchOneByOne
|
||||
"1802": "cc._EventListenerTouchAllAtOnce.checkAvailable(): Invalid EventListenerTouchAllAtOnce!", //touchAllAtOnce
|
||||
"1803": "cc._EventListenerAcceleration.checkAvailable(): _onAccelerationEvent must be non-nil", //acceleration
|
||||
"1800": "Keyboard EventListener checkAvailable(): Invalid EventListenerKeyboard!", //keyboard
|
||||
"1801": "TouchOneByOne EventListener checkAvailable(): Invalid EventListenerTouchOneByOne!", //touchOneByOne
|
||||
"1802": "TouchAllAtOnce EventListener checkAvailable(): Invalid EventListenerTouchAllAtOnce!", //touchAllAtOnce
|
||||
"1803": "Acceleration EventListener checkAvailable(): _onAccelerationEvent must be non-nil", //acceleration
|
||||
//EventListener: 1900
|
||||
"1900": "Invalid parameter.", //create
|
||||
//__getListenerID: 2000
|
||||
|
||||
+18
-27
@@ -24,6 +24,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('../core/platform/CCClass');
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
@@ -33,7 +35,8 @@
|
||||
* !#zh Action 类是所有动作类型的基类。
|
||||
* @class Action
|
||||
*/
|
||||
cc.Action = cc._Class.extend({
|
||||
cc.Action = cc.Class({
|
||||
name: 'cc.Action',
|
||||
|
||||
//**************Public Functions***********
|
||||
|
||||
@@ -185,12 +188,12 @@ cc.Action.TAG_INVALID = -1;
|
||||
* @class FiniteTimeAction
|
||||
* @extends Action
|
||||
*/
|
||||
cc.FiniteTimeAction = cc.Action.extend({
|
||||
//! duration in seconds
|
||||
_duration:0,
|
||||
cc.FiniteTimeAction = cc.Class({
|
||||
name: 'cc.FiniteTimeAction',
|
||||
extends: cc.Action,
|
||||
|
||||
ctor:function () {
|
||||
cc.Action.prototype.ctor.call(this);
|
||||
//! duration in seconds
|
||||
this._duration = 0;
|
||||
},
|
||||
|
||||
@@ -259,12 +262,11 @@ cc.FiniteTimeAction = cc.Action.extend({
|
||||
* @param {ActionInterval} action
|
||||
* @param {Number} speed
|
||||
*/
|
||||
cc.Speed = cc.Action.extend({
|
||||
_speed:0.0,
|
||||
_innerAction:null,
|
||||
cc.Speed = cc.Class({
|
||||
name: 'cc.Speed',
|
||||
extends: cc.Action,
|
||||
|
||||
ctor:function (action, speed) {
|
||||
cc.Action.prototype.ctor.call(this);
|
||||
this._speed = 0;
|
||||
this._innerAction = null;
|
||||
|
||||
@@ -410,22 +412,9 @@ cc.speed = function (action, speed) {
|
||||
* @class
|
||||
* @extends Action
|
||||
*/
|
||||
cc.Follow = cc.Action.extend({
|
||||
// node to follow
|
||||
_followedNode:null,
|
||||
// whether camera should be limited to certain area
|
||||
_boundarySet:false,
|
||||
// if screen size is bigger than the boundary - update not needed
|
||||
_boundaryFullyCovered:false,
|
||||
// fast access to the screen dimensions
|
||||
_halfScreenSize:null,
|
||||
_fullScreenSize:null,
|
||||
_worldRect:null,
|
||||
|
||||
leftBoundary:0.0,
|
||||
rightBoundary:0.0,
|
||||
topBoundary:0.0,
|
||||
bottomBoundary:0.0,
|
||||
cc.Follow = cc.Class({
|
||||
name: 'cc.Follow',
|
||||
extends: cc.Action,
|
||||
|
||||
/*
|
||||
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
|
||||
@@ -435,11 +424,13 @@ cc.Follow = cc.Action.extend({
|
||||
* @param {Rect} rect
|
||||
*/
|
||||
ctor:function (followedNode, rect) {
|
||||
cc.Action.prototype.ctor.call(this);
|
||||
// node to follow
|
||||
this._followedNode = null;
|
||||
// whether camera should be limited to certain area
|
||||
this._boundarySet = false;
|
||||
|
||||
// if screen size is bigger than the boundary - update not needed
|
||||
this._boundaryFullyCovered = false;
|
||||
// fast access to the screen dimensions
|
||||
this._halfScreenSize = null;
|
||||
this._fullScreenSize = null;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
* @param {Number} t
|
||||
* @return {Vec2}
|
||||
*/
|
||||
cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
|
||||
function cardinalSplineAt (p0, p1, p2, p3, tension, t) {
|
||||
var t2 = t * t;
|
||||
var t3 = t2 * t;
|
||||
|
||||
@@ -76,7 +76,7 @@ cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
|
||||
* @param {Number} pos
|
||||
* @return {Array}
|
||||
*/
|
||||
cc.getControlPointAt = function (controlPoints, pos) {
|
||||
function getControlPointAt (controlPoints, pos) {
|
||||
var p = Math.min(controlPoints.length - 1, Math.max(pos, 0));
|
||||
return controlPoints[p];
|
||||
};
|
||||
@@ -112,18 +112,17 @@ function cloneControlPoints (controlPoints) {
|
||||
* //create a cc.CardinalSplineTo
|
||||
* var action1 = cc.cardinalSplineTo(3, array, 0);
|
||||
*/
|
||||
cc.CardinalSplineTo = cc.ActionInterval.extend({
|
||||
/* Array of control points */
|
||||
_points:null,
|
||||
_deltaT:0,
|
||||
_tension:0,
|
||||
_previousPosition:null,
|
||||
_accumulatedDiff:null,
|
||||
cc.CardinalSplineTo = cc.Class({
|
||||
name: 'cc.CardinalSplineTo',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor: function (duration, points, tension) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
|
||||
/* Array of control points */
|
||||
this._points = [];
|
||||
this._deltaT = 0;
|
||||
this._tension = 0;
|
||||
this._previousPosition = null;
|
||||
this._accumulatedDiff = null;
|
||||
tension !== undefined && this.initWithDuration(duration, points, tension);
|
||||
},
|
||||
|
||||
@@ -170,11 +169,11 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
|
||||
lt = (dt - locDT * p) / locDT;
|
||||
}
|
||||
|
||||
var newPos = cc.cardinalSplineAt(
|
||||
cc.getControlPointAt(ps, p - 1),
|
||||
cc.getControlPointAt(ps, p - 0),
|
||||
cc.getControlPointAt(ps, p + 1),
|
||||
cc.getControlPointAt(ps, p + 2),
|
||||
var newPos = cardinalSplineAt(
|
||||
getControlPointAt(ps, p - 1),
|
||||
getControlPointAt(ps, p - 0),
|
||||
getControlPointAt(ps, p + 1),
|
||||
getControlPointAt(ps, p + 2),
|
||||
this._tension, lt);
|
||||
|
||||
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
|
||||
@@ -260,13 +259,12 @@ cc.cardinalSplineTo = function (duration, points, tension) {
|
||||
* //create a cc.CardinalSplineBy
|
||||
* var action1 = cc.cardinalSplineBy(3, array, 0);
|
||||
*/
|
||||
cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
|
||||
_startPosition:null,
|
||||
cc.CardinalSplineBy = cc.Class({
|
||||
name: 'cc.CardinalSplineBy',
|
||||
extends: cc.CardinalSplineTo,
|
||||
|
||||
ctor:function (duration, points, tension) {
|
||||
cc.CardinalSplineTo.prototype.ctor.call(this);
|
||||
this._startPosition = cc.p(0, 0);
|
||||
|
||||
tension !== undefined && this.initWithDuration(duration, points, tension);
|
||||
},
|
||||
|
||||
@@ -362,7 +360,9 @@ cc.cardinalSplineBy = function (duration, points, tension) {
|
||||
* @example
|
||||
* var action1 = cc.catmullRomTo(3, array);
|
||||
*/
|
||||
cc.CatmullRomTo = cc.CardinalSplineTo.extend({
|
||||
cc.CatmullRomTo = cc.Class({
|
||||
name: 'cc.CatmullRomTo',
|
||||
extends: cc.CardinalSplineTo,
|
||||
|
||||
ctor: function(dt, points) {
|
||||
points && this.initWithDuration(dt, points);
|
||||
@@ -409,10 +409,11 @@ cc.catmullRomTo = function (dt, points) {
|
||||
* @example
|
||||
* var action1 = cc.catmullRomBy(3, array);
|
||||
*/
|
||||
cc.CatmullRomBy = cc.CardinalSplineBy.extend({
|
||||
cc.CatmullRomBy = cc.Class({
|
||||
name: 'cc.CatmullRomBy',
|
||||
extends: cc.CardinalSplineBy,
|
||||
|
||||
ctor: function(dt, points) {
|
||||
cc.CardinalSplineBy.prototype.ctor.call(this);
|
||||
points && this.initWithDuration(dt, points);
|
||||
},
|
||||
|
||||
|
||||
+291
-1634
File diff suppressed because it is too large
Load Diff
@@ -34,7 +34,9 @@
|
||||
* @class ActionInstant
|
||||
* @extends FiniteTimeAction
|
||||
*/
|
||||
cc.ActionInstant = cc.FiniteTimeAction.extend({
|
||||
cc.ActionInstant = cc.Class({
|
||||
name: 'cc.ActionInstant',
|
||||
extends: cc.FiniteTimeAction,
|
||||
isDone:function () {
|
||||
return true;
|
||||
},
|
||||
@@ -72,7 +74,9 @@ cc.ActionInstant = cc.FiniteTimeAction.extend({
|
||||
* @class Show
|
||||
* @extends ActionInstant
|
||||
*/
|
||||
cc.Show = cc.ActionInstant.extend({
|
||||
cc.Show = cc.Class({
|
||||
name: 'cc.Show',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
update:function (dt) {
|
||||
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
|
||||
@@ -109,7 +113,9 @@ cc.show = function () {
|
||||
* @class Hide
|
||||
* @extends ActionInstant
|
||||
*/
|
||||
cc.Hide = cc.ActionInstant.extend({
|
||||
cc.Hide = cc.Class({
|
||||
name: 'cc.Hide',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
update:function (dt) {
|
||||
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
|
||||
@@ -146,7 +152,9 @@ cc.hide = function () {
|
||||
* @class ToggleVisibility
|
||||
* @extends ActionInstant
|
||||
*/
|
||||
cc.ToggleVisibility = cc.ActionInstant.extend({
|
||||
cc.ToggleVisibility = cc.Class({
|
||||
name: 'cc.ToggleVisibility',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
update:function (dt) {
|
||||
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
|
||||
@@ -188,12 +196,12 @@ cc.toggleVisibility = function () {
|
||||
* // example
|
||||
* var removeSelfAction = new cc.RemoveSelf(false);
|
||||
*/
|
||||
cc.RemoveSelf = cc.ActionInstant.extend({
|
||||
_isNeedCleanUp: true,
|
||||
cc.RemoveSelf = cc.Class({
|
||||
name: 'cc.RemoveSelf',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
ctor:function(isNeedCleanUp){
|
||||
cc.FiniteTimeAction.prototype.ctor.call(this);
|
||||
|
||||
this._isNeedCleanUp = true;
|
||||
isNeedCleanUp !== undefined && this.init(isNeedCleanUp);
|
||||
},
|
||||
|
||||
@@ -239,11 +247,11 @@ cc.removeSelf = function(isNeedCleanUp){
|
||||
* @example
|
||||
* var flipXAction = new cc.FlipX(true);
|
||||
*/
|
||||
cc.FlipX = cc.ActionInstant.extend({
|
||||
_flippedX:false,
|
||||
cc.FlipX = cc.Class({
|
||||
name: 'cc.FlipX',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
ctor:function(flip){
|
||||
cc.FiniteTimeAction.prototype.ctor.call(this);
|
||||
this._flippedX = false;
|
||||
flip !== undefined && this.initWithFlipX(flip);
|
||||
},
|
||||
@@ -294,13 +302,12 @@ cc.flipX = function (flip) {
|
||||
* @example
|
||||
* var flipYAction = new cc.FlipY(true);
|
||||
*/
|
||||
cc.FlipY = cc.ActionInstant.extend({
|
||||
_flippedY:false,
|
||||
cc.FlipY = cc.Class({
|
||||
name: 'cc.FlipY',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
ctor: function(flip){
|
||||
cc.FiniteTimeAction.prototype.ctor.call(this);
|
||||
this._flippedY = false;
|
||||
|
||||
flip !== undefined && this.initWithFlipY(flip);
|
||||
},
|
||||
|
||||
@@ -352,12 +359,11 @@ cc.flipY = function (flip) {
|
||||
* var placeAction = new cc.Place(cc.p(200, 200));
|
||||
* var placeAction = new cc.Place(200, 200);
|
||||
*/
|
||||
cc.Place = cc.ActionInstant.extend({
|
||||
_x: 0,
|
||||
_y: 0,
|
||||
cc.Place = cc.Class({
|
||||
name: 'cc.Place',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
ctor:function(pos, y){
|
||||
cc.FiniteTimeAction.prototype.ctor.call(this);
|
||||
this._x = 0;
|
||||
this._y = 0;
|
||||
|
||||
@@ -425,10 +431,9 @@ cc.place = function (pos, y) {
|
||||
* // CallFunc with data
|
||||
* var finish = new cc.CallFunc(this.removeFromParentAndCleanup, this, true);
|
||||
*/
|
||||
cc.CallFunc = cc.ActionInstant.extend({
|
||||
_selectorTarget:null,
|
||||
_function:null,
|
||||
_data:null,
|
||||
cc.CallFunc = cc.Class({
|
||||
name: 'cc.CallFunc',
|
||||
extends: cc.ActionInstant,
|
||||
|
||||
/*
|
||||
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
|
||||
@@ -438,8 +443,9 @@ cc.CallFunc = cc.ActionInstant.extend({
|
||||
* @param {*} [data=null] data for function, it accepts all data types.
|
||||
*/
|
||||
ctor:function(selector, selectorTarget, data){
|
||||
cc.FiniteTimeAction.prototype.ctor.call(this);
|
||||
|
||||
this._selectorTarget = null;
|
||||
this._function = null;
|
||||
this._data = null;
|
||||
this.initWithFunction(selector, selectorTarget, data);
|
||||
},
|
||||
|
||||
|
||||
+142
-327
@@ -46,24 +46,20 @@
|
||||
* @extends FiniteTimeAction
|
||||
* @param {Number} d duration in seconds
|
||||
*/
|
||||
cc.ActionInterval = cc.FiniteTimeAction.extend({
|
||||
_elapsed:0,
|
||||
_firstTick:false,
|
||||
_easeList: null,
|
||||
_timesForRepeat:1,
|
||||
_repeatForever: false,
|
||||
_repeatMethod: false,//Compatible with repeat class, Discard after can be deleted
|
||||
_speed: 1,
|
||||
_speedMethod: false,//Compatible with speed class, Discard after can be deleted
|
||||
cc.ActionInterval = cc.Class({
|
||||
name: 'cc.ActionInterval',
|
||||
extends: cc.FiniteTimeAction,
|
||||
|
||||
ctor:function (d) {
|
||||
this.MAX_VALUE = 2;
|
||||
this._elapsed = 0;
|
||||
this._firstTick = false;
|
||||
this._easeList = null;
|
||||
this._speed = 1;
|
||||
this._timesForRepeat = 1;
|
||||
this._repeatForever = false;
|
||||
this.MAX_VALUE = 2;
|
||||
this._repeatMethod = false;//Compatible with repeat class, Discard after can be deleted
|
||||
this._speedMethod = false;//Compatible with repeat class, Discard after can be deleted
|
||||
cc.FiniteTimeAction.prototype.ctor.call(this);
|
||||
d !== undefined && this.initWithDuration(d);
|
||||
},
|
||||
|
||||
@@ -302,15 +298,15 @@ cc.actionInterval = function (d) {
|
||||
* // create sequence with array
|
||||
* var seq = new cc.Sequence(actArray);
|
||||
*/
|
||||
cc.Sequence = cc.ActionInterval.extend({
|
||||
_actions:null,
|
||||
_split:null,
|
||||
_last:0,
|
||||
_reversed:false,
|
||||
cc.Sequence = cc.Class({
|
||||
name: 'cc.Sequence',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (tempArray) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._actions = [];
|
||||
this._split = null;
|
||||
this._last = 0;
|
||||
this._reversed = false;
|
||||
|
||||
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
|
||||
if (paramArray.length === 1) {
|
||||
@@ -486,16 +482,16 @@ cc.Sequence._actionOneTwo = function (actionOne, actionTwo) {
|
||||
* @example
|
||||
* var rep = new cc.Repeat(cc.sequence(jump2, jump1), 5);
|
||||
*/
|
||||
cc.Repeat = cc.ActionInterval.extend({
|
||||
_times:0,
|
||||
_total:0,
|
||||
_nextDt:0,
|
||||
_actionInstant:false,
|
||||
_innerAction:null, //CCFiniteTimeAction
|
||||
cc.Repeat = cc.Class({
|
||||
name: 'cc.Repeat',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor: function (action, times) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
|
||||
this._times = 0;
|
||||
this._total = 0;
|
||||
this._nextDt = 0;
|
||||
this._actionInstant = false;
|
||||
this._innerAction = null;
|
||||
times !== undefined && this.initWithAction(action, times);
|
||||
},
|
||||
|
||||
@@ -633,13 +629,12 @@ cc.repeat = function (action, times) {
|
||||
* @example
|
||||
* var rep = new cc.RepeatForever(cc.sequence(jump2, jump1), 5);
|
||||
*/
|
||||
cc.RepeatForever = cc.ActionInterval.extend({
|
||||
_innerAction:null, //CCActionInterval
|
||||
cc.RepeatForever = cc.Class({
|
||||
name: 'cc.RepeatForever',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (action) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._innerAction = null;
|
||||
|
||||
action && this.initWithAction(action);
|
||||
},
|
||||
|
||||
@@ -730,12 +725,11 @@ cc.repeatForever = function (action) {
|
||||
* @class Spawn
|
||||
* @extends ActionInterval
|
||||
*/
|
||||
cc.Spawn = cc.ActionInterval.extend({
|
||||
_one:null,
|
||||
_two:null,
|
||||
cc.Spawn = cc.Class({
|
||||
name: 'cc.Spawn',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (tempArray) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._one = null;
|
||||
this._two = null;
|
||||
|
||||
@@ -871,18 +865,17 @@ cc.Spawn._actionOneTwo = function (action1, action2) {
|
||||
* @example
|
||||
* var rotateTo = new cc.RotateTo(2, 61.0);
|
||||
*/
|
||||
cc.RotateTo = cc.ActionInterval.extend({
|
||||
_dstAngleX:0,
|
||||
_startAngleX:0,
|
||||
_diffAngleX:0,
|
||||
|
||||
_dstAngleY:0,
|
||||
_startAngleY:0,
|
||||
_diffAngleY:0,
|
||||
cc.RotateTo = cc.Class({
|
||||
name: 'cc.RotateTo',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, deltaAngleX, deltaAngleY) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
|
||||
this._dstAngleX = 0;
|
||||
this._startAngleX = 0;
|
||||
this._diffAngleX = 0;
|
||||
this._dstAngleY = 0;
|
||||
this._startAngleY = 0;
|
||||
this._diffAngleY = 0;
|
||||
deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY);
|
||||
},
|
||||
|
||||
@@ -975,15 +968,15 @@ cc.rotateTo = function (duration, deltaAngleX, deltaAngleY) {
|
||||
* @example
|
||||
* var actionBy = new cc.RotateBy(2, 360);
|
||||
*/
|
||||
cc.RotateBy = cc.ActionInterval.extend({
|
||||
_angleX:0,
|
||||
_startAngleX:0,
|
||||
_angleY:0,
|
||||
_startAngleY:0,
|
||||
cc.RotateBy = cc.Class({
|
||||
name: 'cc.RotateBy',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor: function (duration, deltaAngleX, deltaAngleY) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
|
||||
this._angleX = 0;
|
||||
this._startAngleX = 0;
|
||||
this._angleY = 0;
|
||||
this._startAngleY = 0;
|
||||
deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY);
|
||||
},
|
||||
|
||||
@@ -1066,14 +1059,11 @@ cc.rotateBy = function (duration, deltaAngleX, deltaAngleY) {
|
||||
* @example
|
||||
* var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40));
|
||||
*/
|
||||
cc.MoveBy = cc.ActionInterval.extend({
|
||||
_positionDelta:null,
|
||||
_startPosition:null,
|
||||
_previousPosition:null,
|
||||
cc.MoveBy = cc.Class({
|
||||
name: 'cc.MoveBy',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, deltaPos, deltaY) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
|
||||
this._positionDelta = cc.p(0, 0);
|
||||
this._startPosition = cc.p(0, 0);
|
||||
this._previousPosition = cc.p(0, 0);
|
||||
@@ -1184,13 +1174,12 @@ cc.moveBy = function (duration, deltaPos, deltaY) {
|
||||
* @example
|
||||
* var actionBy = new cc.MoveTo(2, cc.p(80, 80));
|
||||
*/
|
||||
cc.MoveTo = cc.MoveBy.extend({
|
||||
_endPosition:null,
|
||||
cc.MoveTo = cc.Class({
|
||||
name: 'cc.MoveTo',
|
||||
extends: cc.MoveBy,
|
||||
|
||||
ctor:function (duration, position, y) {
|
||||
cc.MoveBy.prototype.ctor.call(this);
|
||||
this._endPosition = cc.p(0, 0);
|
||||
|
||||
position !== undefined && this.initWithDuration(duration, position, y);
|
||||
},
|
||||
|
||||
@@ -1258,19 +1247,19 @@ cc.moveTo = function (duration, position, y) {
|
||||
* @example
|
||||
* var actionTo = new cc.SkewTo(2, 37.2, -37.2);
|
||||
*/
|
||||
cc.SkewTo = cc.ActionInterval.extend({
|
||||
_skewX:0,
|
||||
_skewY:0,
|
||||
_startSkewX:0,
|
||||
_startSkewY:0,
|
||||
_endSkewX:0,
|
||||
_endSkewY:0,
|
||||
_deltaX:0,
|
||||
_deltaY:0,
|
||||
cc.SkewTo = cc.Class({
|
||||
name: 'cc.SkewTo',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor: function (t, sx, sy) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
|
||||
this._skewX = 0;
|
||||
this._skewY = 0;
|
||||
this._startSkewX = 0;
|
||||
this._startSkewY = 0;
|
||||
this._endSkewX = 0;
|
||||
this._endSkewY = 0;
|
||||
this._deltaX = 0;
|
||||
this._deltaY = 0;
|
||||
sy !== undefined && this.initWithDuration(t, sx, sy);
|
||||
},
|
||||
|
||||
@@ -1350,10 +1339,11 @@ cc.skewTo = function (t, sx, sy) {
|
||||
* @param {Number} sx skew in degrees for X axis
|
||||
* @param {Number} sy skew in degrees for Y axis
|
||||
*/
|
||||
cc.SkewBy = cc.SkewTo.extend({
|
||||
cc.SkewBy = cc.Class({
|
||||
name: 'cc.SkewBy',
|
||||
extends: cc.SkewTo,
|
||||
|
||||
ctor: function(t, sx, sy) {
|
||||
cc.SkewTo.prototype.ctor.call(this);
|
||||
sy !== undefined && this.initWithDuration(t, sx, sy);
|
||||
},
|
||||
|
||||
@@ -1430,18 +1420,16 @@ cc.skewBy = function (t, sx, sy) {
|
||||
* var actionBy = new cc.JumpBy(2, cc.p(300, 0), 50, 4);
|
||||
* var actionBy = new cc.JumpBy(2, 300, 0, 50, 4);
|
||||
*/
|
||||
cc.JumpBy = cc.ActionInterval.extend({
|
||||
_startPosition:null,
|
||||
_delta:null,
|
||||
_height:0,
|
||||
_jumps:0,
|
||||
_previousPosition:null,
|
||||
cc.JumpBy = cc.Class({
|
||||
name: 'cc.JumpBy',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, position, y, height, jumps) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._startPosition = cc.p(0, 0);
|
||||
this._previousPosition = cc.p(0, 0);
|
||||
this._delta = cc.p(0, 0);
|
||||
this._height = 0;
|
||||
this._jumps = 0;
|
||||
|
||||
height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
|
||||
},
|
||||
@@ -1561,13 +1549,12 @@ cc.jumpBy = function (duration, position, y, height, jumps) {
|
||||
* var actionTo = new cc.JumpTo(2, cc.p(300, 0), 50, 4);
|
||||
* var actionTo = new cc.JumpTo(2, 300, 0, 50, 4);
|
||||
*/
|
||||
cc.JumpTo = cc.JumpBy.extend({
|
||||
_endPosition:null,
|
||||
cc.JumpTo = cc.Class({
|
||||
name: 'cc.JumpTo',
|
||||
extends: cc.JumpBy,
|
||||
|
||||
ctor:function (duration, position, y, height, jumps) {
|
||||
cc.JumpBy.prototype.ctor.call(this);
|
||||
this._endPosition = cc.p(0, 0);
|
||||
|
||||
height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
|
||||
},
|
||||
/*
|
||||
@@ -1630,22 +1617,6 @@ cc.jumpTo = function (duration, position, y, height, jumps) {
|
||||
return new cc.JumpTo(duration, position, y, height, jumps);
|
||||
};
|
||||
|
||||
/*
|
||||
* @method bezierAt
|
||||
* @param {Number} a
|
||||
* @param {Number} b
|
||||
* @param {Number} c
|
||||
* @param {Number} d
|
||||
* @param {Number} t
|
||||
* @return {Number}
|
||||
*/
|
||||
cc.bezierAt = function (a, b, c, d, t) {
|
||||
return (Math.pow(1 - t, 3) * a +
|
||||
3 * t * (Math.pow(1 - t, 2)) * b +
|
||||
3 * Math.pow(t, 2) * (1 - t) * c +
|
||||
Math.pow(t, 3) * d );
|
||||
};
|
||||
|
||||
/* An action that moves the target with a cubic Bezier curve by a certain distance.
|
||||
* Relative to its movement.
|
||||
* @class BezierBy
|
||||
@@ -1656,17 +1627,20 @@ cc.bezierAt = function (a, b, c, d, t) {
|
||||
* var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
|
||||
* var bezierForward = new cc.BezierBy(3, bezier);
|
||||
*/
|
||||
cc.BezierBy = cc.ActionInterval.extend({
|
||||
_config:null,
|
||||
_startPosition:null,
|
||||
_previousPosition:null,
|
||||
function bezierAt (a, b, c, d, t) {
|
||||
return (Math.pow(1 - t, 3) * a +
|
||||
3 * t * (Math.pow(1 - t, 2)) * b +
|
||||
3 * Math.pow(t, 2) * (1 - t) * c +
|
||||
Math.pow(t, 3) * d );
|
||||
};
|
||||
cc.BezierBy = cc.Class({
|
||||
name: 'cc.BezierBy',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (t, c) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._config = [];
|
||||
this._startPosition = cc.p(0, 0);
|
||||
this._previousPosition = cc.p(0, 0);
|
||||
|
||||
c && this.initWithDuration(t, c);
|
||||
},
|
||||
|
||||
@@ -1720,8 +1694,8 @@ cc.BezierBy = cc.ActionInterval.extend({
|
||||
var yc = locConfig[1].y;
|
||||
var yd = locConfig[2].y;
|
||||
|
||||
var x = cc.bezierAt(xa, xb, xc, xd, dt);
|
||||
var y = cc.bezierAt(ya, yb, yc, yd, dt);
|
||||
var x = bezierAt(xa, xb, xc, xd, dt);
|
||||
var y = bezierAt(ya, yb, yc, yd, dt);
|
||||
|
||||
var locStartPosition = this._startPosition;
|
||||
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
|
||||
@@ -1783,11 +1757,11 @@ cc.bezierBy = function (t, c) {
|
||||
* var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
|
||||
* var bezierTo = new cc.BezierTo(2, bezier);
|
||||
*/
|
||||
cc.BezierTo = cc.BezierBy.extend({
|
||||
_toConfig:null,
|
||||
cc.BezierTo = cc.Class({
|
||||
name: 'cc.BezierTo',
|
||||
extends: cc.BezierBy,
|
||||
|
||||
ctor:function (t, c) {
|
||||
cc.BezierBy.prototype.ctor.call(this);
|
||||
this._toConfig = [];
|
||||
c && this.initWithDuration(t, c);
|
||||
},
|
||||
@@ -1855,18 +1829,19 @@ cc.bezierTo = function (t, c) {
|
||||
* // It scales to 0.5 in x and 2 in Y
|
||||
* var actionTo = new cc.ScaleTo(2, 0.5, 2);
|
||||
*/
|
||||
cc.ScaleTo = cc.ActionInterval.extend({
|
||||
_scaleX:1,
|
||||
_scaleY:1,
|
||||
_startScaleX:1,
|
||||
_startScaleY:1,
|
||||
_endScaleX:0,
|
||||
_endScaleY:0,
|
||||
_deltaX:0,
|
||||
_deltaY:0,
|
||||
cc.ScaleTo = cc.Class({
|
||||
name: 'cc.ScaleTo',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, sx, sy) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._scaleX = 1;
|
||||
this._scaleY = 1;
|
||||
this._startScaleX = 1;
|
||||
this._startScaleY = 1;
|
||||
this._endScaleX = 0;
|
||||
this._endScaleY = 0;
|
||||
this._deltaX = 0;
|
||||
this._deltaY = 0;
|
||||
sx !== undefined && this.initWithDuration(duration, sx, sy);
|
||||
},
|
||||
|
||||
@@ -1935,7 +1910,10 @@ cc.scaleTo = function (duration, sx, sy) { //function overload
|
||||
* @class ScaleBy
|
||||
* @extends ScaleTo
|
||||
*/
|
||||
cc.ScaleBy = cc.ScaleTo.extend({
|
||||
cc.ScaleBy = cc.Class({
|
||||
name: 'cc.ScaleBy',
|
||||
extends: cc.ScaleTo,
|
||||
|
||||
startWithTarget:function (target) {
|
||||
cc.ScaleTo.prototype.startWithTarget.call(this, target);
|
||||
this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX;
|
||||
@@ -1985,12 +1963,13 @@ cc.scaleBy = function (duration, sx, sy) {
|
||||
* @example
|
||||
* var action = new cc.Blink(2, 10);
|
||||
*/
|
||||
cc.Blink = cc.ActionInterval.extend({
|
||||
_times:0,
|
||||
_originalState:false,
|
||||
cc.Blink = cc.Class({
|
||||
name: 'cc.Blink',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, blinks) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._times = 0;
|
||||
this._originalState = false;
|
||||
blinks !== undefined && this.initWithDuration(duration, blinks);
|
||||
},
|
||||
|
||||
@@ -2065,12 +2044,13 @@ cc.blink = function (duration, blinks) {
|
||||
* @example
|
||||
* var action = new cc.FadeTo(1.0, 0);
|
||||
*/
|
||||
cc.FadeTo = cc.ActionInterval.extend({
|
||||
_toOpacity:0,
|
||||
_fromOpacity:0,
|
||||
cc.FadeTo = cc.Class({
|
||||
name: 'cc.FadeTo',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, opacity) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._toOpacity = 0;
|
||||
this._fromOpacity = 0;
|
||||
opacity !== undefined && this.initWithDuration(duration, opacity);
|
||||
},
|
||||
|
||||
@@ -2130,13 +2110,14 @@ cc.fadeTo = function (duration, opacity) {
|
||||
* @extends FadeTo
|
||||
* @param {Number} duration duration in seconds
|
||||
*/
|
||||
cc.FadeIn = cc.FadeTo.extend({
|
||||
_reverseAction: null,
|
||||
cc.FadeIn = cc.Class({
|
||||
name: 'cc.FadeIn',
|
||||
extends: cc.FadeTo,
|
||||
|
||||
ctor:function (duration) {
|
||||
cc.FadeTo.prototype.ctor.call(this);
|
||||
if (duration == null)
|
||||
duration = 0;
|
||||
this._reverseAction = null;
|
||||
this.initWithDuration(duration, 255);
|
||||
},
|
||||
|
||||
@@ -2183,12 +2164,14 @@ cc.fadeIn = function (duration) {
|
||||
* @extends FadeTo
|
||||
* @param {Number} duration duration in seconds
|
||||
*/
|
||||
cc.FadeOut = cc.FadeTo.extend({
|
||||
cc.FadeOut = cc.Class({
|
||||
name: 'cc.FadeOut',
|
||||
extends: cc.FadeTo,
|
||||
|
||||
ctor:function (duration) {
|
||||
cc.FadeTo.prototype.ctor.call(this);
|
||||
if (duration == null)
|
||||
duration = 0;
|
||||
this._reverseAction = null;
|
||||
this.initWithDuration(duration, 0);
|
||||
},
|
||||
|
||||
@@ -2234,12 +2217,11 @@ cc.fadeOut = function (d) {
|
||||
* @example
|
||||
* var action = new cc.TintTo(2, 255, 0, 255);
|
||||
*/
|
||||
cc.TintTo = cc.ActionInterval.extend({
|
||||
_to:null,
|
||||
_from:null,
|
||||
cc.TintTo = cc.Class({
|
||||
name: 'cc.TintTo',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, red, green, blue) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._to = cc.color(0, 0, 0);
|
||||
this._from = cc.color(0, 0, 0);
|
||||
|
||||
@@ -2325,17 +2307,17 @@ cc.tintTo = function (duration, red, green, blue) {
|
||||
* @example
|
||||
* var action = new cc.TintBy(2, -127, -255, -127);
|
||||
*/
|
||||
cc.TintBy = cc.ActionInterval.extend({
|
||||
_deltaR:0,
|
||||
_deltaG:0,
|
||||
_deltaB:0,
|
||||
|
||||
_fromR:0,
|
||||
_fromG:0,
|
||||
_fromB:0,
|
||||
cc.TintBy = cc.Class({
|
||||
name: 'cc.TintBy',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (duration, deltaRed, deltaGreen, deltaBlue) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._deltaR = 0;
|
||||
this._deltaG = 0;
|
||||
this._deltaB = 0;
|
||||
this._fromR = 0;
|
||||
this._fromG = 0;
|
||||
this._fromB = 0;
|
||||
deltaBlue !== undefined && this.initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
|
||||
},
|
||||
|
||||
@@ -2412,7 +2394,10 @@ cc.tintBy = function (duration, deltaRed, deltaGreen, deltaBlue) {
|
||||
* @class DelayTime
|
||||
* @extends ActionInterval
|
||||
*/
|
||||
cc.DelayTime = cc.ActionInterval.extend({
|
||||
cc.DelayTime = cc.Class({
|
||||
name: 'cc.DelayTime',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
update:function (dt) {},
|
||||
|
||||
reverse:function () {
|
||||
@@ -2457,13 +2442,12 @@ cc.delayTime = function (d) {
|
||||
* @example
|
||||
* var reverse = new cc.ReverseTime(this);
|
||||
*/
|
||||
cc.ReverseTime = cc.ActionInterval.extend({
|
||||
_other:null,
|
||||
cc.ReverseTime = cc.Class({
|
||||
name: 'cc.ReverseTime',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor:function (action) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._other = null;
|
||||
|
||||
action && this.initWithAction(action);
|
||||
},
|
||||
|
||||
@@ -2527,176 +2511,6 @@ cc.reverseTime = function (action) {
|
||||
return new cc.ReverseTime(action);
|
||||
};
|
||||
|
||||
/*
|
||||
* This API is deprecated, will be replaced by new API from {{#crossLink "Animation"}}cc.Animation{{/crossLink}}
|
||||
* Animates a sprite given the name of an Animation
|
||||
* @class Animate
|
||||
* @extends ActionInterval
|
||||
* @param {SpriteFrameAnimation} animation
|
||||
* @example
|
||||
* // create the animation with animation
|
||||
* var anim = new cc.Animate(dance_grey);
|
||||
*/
|
||||
cc.Animate = cc.ActionInterval.extend({
|
||||
_animation:null,
|
||||
_nextFrame:0,
|
||||
_origFrame:null,
|
||||
_executedLoops:0,
|
||||
_splitTimes: null,
|
||||
_currFrameIndex:0,
|
||||
|
||||
ctor:function (animation) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._splitTimes = [];
|
||||
|
||||
animation && this.initWithAnimation(animation);
|
||||
},
|
||||
|
||||
/*
|
||||
* @return {SpriteFrameAnimation}
|
||||
*/
|
||||
getAnimation:function () {
|
||||
return this._animation;
|
||||
},
|
||||
|
||||
/*
|
||||
* @param {SpriteFrameAnimation} animation
|
||||
*/
|
||||
setAnimation:function (animation) {
|
||||
this._animation = animation;
|
||||
},
|
||||
|
||||
/*
|
||||
* Gets the index of sprite frame currently displayed.
|
||||
* @return {Number}
|
||||
*/
|
||||
getCurrentFrameIndex: function () {
|
||||
return this._currFrameIndex;
|
||||
},
|
||||
|
||||
/*
|
||||
* @param {SpriteFrameAnimation} animation
|
||||
* @return {Boolean}
|
||||
*/
|
||||
initWithAnimation:function (animation) {
|
||||
if(!animation)
|
||||
throw new Error(cc._getError(1030));
|
||||
var singleDuration = animation.getDuration();
|
||||
if (this.initWithDuration(singleDuration * animation.getLoops())) {
|
||||
this._nextFrame = 0;
|
||||
this.setAnimation(animation);
|
||||
|
||||
this._origFrame = null;
|
||||
this._executedLoops = 0;
|
||||
var locTimes = this._splitTimes;
|
||||
locTimes.length = 0;
|
||||
|
||||
var accumUnitsOfTime = 0;
|
||||
var newUnitOfTimeValue = singleDuration / animation.getTotalDelayUnits();
|
||||
|
||||
var frames = animation.getFrames();
|
||||
cc.js.array.verifyType(frames, cc.AnimationFrame);
|
||||
|
||||
for (var i = 0; i < frames.length; i++) {
|
||||
var frame = frames[i];
|
||||
var value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
||||
accumUnitsOfTime += frame.getDelayUnits();
|
||||
locTimes.push(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
clone:function () {
|
||||
var action = new cc.Animate();
|
||||
this._cloneDecoration(action);
|
||||
action.initWithAnimation(this._animation.clone());
|
||||
return action;
|
||||
},
|
||||
|
||||
startWithTarget:function (target) {
|
||||
cc.ActionInterval.prototype.startWithTarget.call(this, target);
|
||||
if (this._animation.getRestoreOriginalFrame())
|
||||
this._origFrame = target.getSpriteFrame();
|
||||
this._nextFrame = 0;
|
||||
this._executedLoops = 0;
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
dt = this._computeEaseTime(dt);
|
||||
// if t==1, ignore. Animation should finish with t==1
|
||||
if (dt < 1.0) {
|
||||
dt *= this._animation.getLoops();
|
||||
|
||||
// new loop? If so, reset frame counter
|
||||
var loopNumber = 0 | dt;
|
||||
if (loopNumber > this._executedLoops) {
|
||||
this._nextFrame = 0;
|
||||
this._executedLoops++;
|
||||
}
|
||||
|
||||
// new t for animations
|
||||
dt = dt % 1.0;
|
||||
}
|
||||
|
||||
var frames = this._animation.getFrames();
|
||||
var numberOfFrames = frames.length, locSplitTimes = this._splitTimes;
|
||||
for (var i = this._nextFrame; i < numberOfFrames; i++) {
|
||||
if (locSplitTimes[i] <= dt) {
|
||||
_currFrameIndex = i;
|
||||
this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame());
|
||||
this._nextFrame = i + 1;
|
||||
} else {
|
||||
// Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
var locAnimation = this._animation;
|
||||
var oldArray = locAnimation.getFrames();
|
||||
var newArray = [];
|
||||
cc.js.array.verifyType(oldArray, cc.AnimationFrame);
|
||||
if (oldArray.length > 0) {
|
||||
for (var i = oldArray.length - 1; i >= 0; i--) {
|
||||
var element = oldArray[i];
|
||||
if (!element)
|
||||
break;
|
||||
newArray.push(element.clone());
|
||||
}
|
||||
}
|
||||
var newAnim = new cc.SpriteFrameAnimation(newArray, locAnimation.getDelayPerUnit(), locAnimation.getLoops());
|
||||
newAnim.setRestoreOriginalFrame(locAnimation.getRestoreOriginalFrame());
|
||||
var action = new cc.Animate(newAnim);
|
||||
this._cloneDecoration(action);
|
||||
this._reverseEaseList(action);
|
||||
|
||||
return action;
|
||||
},
|
||||
|
||||
stop:function () {
|
||||
if (this._animation.getRestoreOriginalFrame() && this.target)
|
||||
this.target.setSpriteFrame(this._origFrame);
|
||||
cc.Action.prototype.stop.call(this);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* create the animate with animation
|
||||
* @method animate
|
||||
* @param {SpriteFrameAnimation} animation
|
||||
* @return {ActionInterval}
|
||||
* @example
|
||||
* // example
|
||||
* // create the animation with animation
|
||||
* var anim = cc.animate(dance_grey);
|
||||
*/
|
||||
cc.animate = function (animation) {
|
||||
return new cc.Animate(animation);
|
||||
};
|
||||
|
||||
/*
|
||||
* <p>
|
||||
* Overrides the target of an action so that it always runs on the target<br/>
|
||||
@@ -2707,12 +2521,13 @@ cc.animate = function (animation) {
|
||||
* @param {Node} target
|
||||
* @param {FiniteTimeAction} action
|
||||
*/
|
||||
cc.TargetedAction = cc.ActionInterval.extend({
|
||||
_action:null,
|
||||
_forcedTarget:null,
|
||||
cc.TargetedAction = cc.Class({
|
||||
name: 'cc.TargetedAction',
|
||||
extends: cc.ActionInterval,
|
||||
|
||||
ctor: function (target, action) {
|
||||
cc.ActionInterval.prototype.ctor.call(this);
|
||||
this._action = null;
|
||||
this._forcedTarget = null;
|
||||
action && this.initWithTarget(target, action);
|
||||
},
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('../core/platform/CCClass');
|
||||
|
||||
/*
|
||||
* @class HashElement
|
||||
* @constructor
|
||||
@@ -57,8 +59,14 @@ var HashElement = function () {
|
||||
* @class ActionManager
|
||||
* @example {@link utils/api/engine/docs/cocos2d/core/CCActionManager/ActionManager.js}
|
||||
*/
|
||||
cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
|
||||
|
||||
cc.ActionManager = function () {
|
||||
this._hashTargets = {};
|
||||
this._arrayTargets = [];
|
||||
this._currentTarget = null;
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
};
|
||||
cc.ActionManager.prototype = {
|
||||
constructor: cc.ActionManager,
|
||||
_elementPool: [],
|
||||
|
||||
_searchElementByTarget:function (arr, target) {
|
||||
@@ -69,12 +77,6 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
|
||||
return null;
|
||||
},
|
||||
|
||||
ctor:function () {
|
||||
this._hashTargets = {};
|
||||
this._arrayTargets = [];
|
||||
this._currentTarget = null;
|
||||
},
|
||||
|
||||
_getElement: function (target, paused) {
|
||||
var element = this._elementPool.pop();
|
||||
if (!element) {
|
||||
@@ -436,7 +438,7 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (CC_TEST) {
|
||||
cc.ActionManager.prototype.isTargetPaused_TEST = function (target) {
|
||||
|
||||
@@ -1,283 +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.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* cc.configuration is a singleton object which contains some openGL variables
|
||||
* @class
|
||||
* @name cc.configuration
|
||||
* @example
|
||||
* var textureSize = cc.configuration.getMaxTextureSize();
|
||||
*/
|
||||
cc.configuration = /** @lends cc.configuration# */{
|
||||
// Type constants
|
||||
/*
|
||||
* ERROR type
|
||||
* @public
|
||||
* @const
|
||||
* @type {Number}
|
||||
*/
|
||||
ERROR:0,
|
||||
|
||||
/*
|
||||
* STRING type
|
||||
* @public
|
||||
* @const
|
||||
* @type {Number}
|
||||
*/
|
||||
STRING:1,
|
||||
|
||||
/*
|
||||
* INT type
|
||||
* @public
|
||||
* @const
|
||||
* @type {Number}
|
||||
*/
|
||||
INT:2,
|
||||
|
||||
/*
|
||||
* DOUBLE type
|
||||
* @public
|
||||
* @const
|
||||
* @type {Number}
|
||||
*/
|
||||
DOUBLE:3,
|
||||
|
||||
/*
|
||||
* BOOLEAN type
|
||||
* @public
|
||||
* @const
|
||||
* @type {Number}
|
||||
*/
|
||||
BOOLEAN:4,
|
||||
|
||||
_maxTextureSize:0,
|
||||
_maxModelviewStackDepth:0,
|
||||
_supportsPVRTC:false,
|
||||
_supportsNPOT:false,
|
||||
_supportsBGRA8888:false,
|
||||
_supportsDiscardFramebuffer:false,
|
||||
_supportsShareableVAO:false,
|
||||
_maxSamplesAllowed:0,
|
||||
_maxTextureUnits:0,
|
||||
_GlExtensions:"",
|
||||
_valueDict:{},
|
||||
|
||||
_inited: false,
|
||||
|
||||
_init:function () {
|
||||
var locValueDict = this._valueDict;
|
||||
locValueDict["cocos2d.x.version"] = cc.ENGINE_VERSION;
|
||||
locValueDict["cocos2d.x.compiled_with_profiler"] = false;
|
||||
locValueDict["cocos2d.x.compiled_with_gl_state_cache"] = cc.macro.ENABLE_GL_STATE_CACHE;
|
||||
this._inited = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* OpenGL Max texture size.
|
||||
* @return {Number}
|
||||
*/
|
||||
getMaxTextureSize:function () {
|
||||
return this._maxTextureSize;
|
||||
},
|
||||
|
||||
/**
|
||||
* OpenGL Max Modelview Stack Depth.
|
||||
* @return {Number}
|
||||
*/
|
||||
getMaxModelviewStackDepth:function () {
|
||||
return this._maxModelviewStackDepth;
|
||||
},
|
||||
|
||||
/**
|
||||
* returns the maximum texture units
|
||||
* @return {Number}
|
||||
*/
|
||||
getMaxTextureUnits:function () {
|
||||
return this._maxTextureUnits;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not the GPU supports NPOT (Non Power Of Two) textures.
|
||||
* OpenGL ES 2.0 already supports NPOT (iOS).
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsNPOT:function () {
|
||||
return this._supportsNPOT;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not PVR Texture Compressed is supported
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsPVRTC: function () {
|
||||
return this._supportsPVRTC;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not ETC Texture Compressed is supported
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsETC: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not S3TC Texture Compressed is supported
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsS3TC: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not ATITC Texture Compressed is supported
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsATITC: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not BGRA8888 textures are supported.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsBGRA8888:function () {
|
||||
return this._supportsBGRA8888;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not glDiscardFramebufferEXT is supported
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsDiscardFramebuffer:function () {
|
||||
return this._supportsDiscardFramebuffer;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether or not shareable VAOs are supported.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
supportsShareableVAO:function () {
|
||||
return this._supportsShareableVAO;
|
||||
},
|
||||
|
||||
/**
|
||||
* returns whether or not an OpenGL is supported
|
||||
* @param {String} searchName
|
||||
*/
|
||||
checkForGLExtension:function (searchName) {
|
||||
return this._GlExtensions.indexOf(searchName) > -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the value of a given key. If the key is not found, it will return the default value
|
||||
* @param {String} key
|
||||
* @param {String|Bool|Number|Object} [default_value=null]
|
||||
* @returns {String|Bool|Number|Object}
|
||||
*/
|
||||
getValue: function(key, default_value){
|
||||
if(!this._inited)
|
||||
this._init();
|
||||
var locValueDict = this._valueDict;
|
||||
if(locValueDict[key])
|
||||
return locValueDict[key];
|
||||
return default_value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets a new key/value pair in the configuration dictionary
|
||||
* @param {string} key
|
||||
* @param {String|Bool|Number|Object} value
|
||||
*/
|
||||
setValue: function(key, value){
|
||||
this._valueDict[key] = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* gathers OpenGL / GPU information
|
||||
*/
|
||||
gatherGPUInfo: function(){
|
||||
if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
|
||||
return;
|
||||
|
||||
if(!this._inited)
|
||||
this._init();
|
||||
var gl = cc._renderContext;
|
||||
var locValueDict = this._valueDict;
|
||||
locValueDict["gl.vendor"] = gl.getParameter(gl.VENDOR);
|
||||
locValueDict["gl.renderer"] = gl.getParameter(gl.RENDERER);
|
||||
locValueDict["gl.version"] = gl.getParameter(gl.VERSION);
|
||||
|
||||
this._GlExtensions = "";
|
||||
var extArr = gl.getSupportedExtensions();
|
||||
for (var i = 0; i < extArr.length; i++)
|
||||
this._GlExtensions += extArr[i] + " ";
|
||||
|
||||
this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
||||
locValueDict["gl.max_texture_size"] = this._maxTextureSize;
|
||||
this._maxTextureUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
||||
locValueDict["gl.max_texture_units"] = this._maxTextureUnits;
|
||||
|
||||
this._supportsPVRTC = this.checkForGLExtension("GL_IMG_texture_compression_pvrtc");
|
||||
locValueDict["gl.supports_PVRTC"] = this._supportsPVRTC;
|
||||
|
||||
this._supportsNPOT = false; //true;
|
||||
locValueDict["gl.supports_NPOT"] = this._supportsNPOT;
|
||||
|
||||
this._supportsBGRA8888 = this.checkForGLExtension("GL_IMG_texture_format_BGRA888");
|
||||
locValueDict["gl.supports_BGRA8888"] = this._supportsBGRA8888;
|
||||
|
||||
this._supportsDiscardFramebuffer = this.checkForGLExtension("GL_EXT_discard_framebuffer");
|
||||
locValueDict["gl.supports_discard_framebuffer"] = this._supportsDiscardFramebuffer;
|
||||
|
||||
this._supportsShareableVAO = this.checkForGLExtension("vertex_array_object");
|
||||
locValueDict["gl.supports_vertex_array_object"] = this._supportsShareableVAO;
|
||||
|
||||
cc.checkGLErrorDebug();
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads a config file. If the keys are already present, then they are going to be replaced. Otherwise the new keys are added.
|
||||
* @param {string} url
|
||||
*/
|
||||
loadConfigFile: function( url){
|
||||
if(!this._inited)
|
||||
this._init();
|
||||
var dict = cc.loader.getRes(url);
|
||||
if(!dict) throw new Error(cc._getError(1102, url));
|
||||
cc.assertID(dict, 1101, url);
|
||||
|
||||
var getDatas = dict["data"];
|
||||
if(!getDatas){
|
||||
cc.logID(1100, url);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add all keys in the existing dictionary
|
||||
for(var selKey in getDatas)
|
||||
this._valueDict[selKey] = getDatas[selKey];
|
||||
}
|
||||
};
|
||||
+150
-155
@@ -25,7 +25,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
const EventTarget = require('./event/event-target');
|
||||
const Class = require('./platform/_CCClass');
|
||||
const AutoReleaseUtils = require('./load-pipeline/auto-release-utils');
|
||||
const ComponentScheduler = require('./component-scheduler');
|
||||
const NodeActivator = require('./node-activator');
|
||||
@@ -103,43 +102,45 @@ const eventManager = require('./event-manager');
|
||||
* @class Director
|
||||
* @extends EventTarget
|
||||
*/
|
||||
cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
ctor: function () {
|
||||
var self = this;
|
||||
EventTarget.call(self);
|
||||
cc.Director = function () {
|
||||
EventTarget.call(this);
|
||||
|
||||
// paused?
|
||||
self._paused = false;
|
||||
// purge?
|
||||
self._purgeDirectorInNextLoop = false;
|
||||
self._animationInterval = 0.0;
|
||||
self._oldAnimationInterval = 0.0;
|
||||
this.invalid = false;
|
||||
// paused?
|
||||
this._paused = false;
|
||||
// purge?
|
||||
this._purgeDirectorInNextLoop = false;
|
||||
this._animationInterval = 0.0;
|
||||
this._oldAnimationInterval = 0.0;
|
||||
|
||||
self._winSizeInPoints = null;
|
||||
this._winSizeInPoints = null;
|
||||
|
||||
// scenes
|
||||
self._loadingScene = '';
|
||||
self._scene = null;
|
||||
// scenes
|
||||
this._loadingScene = '';
|
||||
this._scene = null;
|
||||
|
||||
// FPS
|
||||
self._totalFrames = 0;
|
||||
// FPS
|
||||
this._totalFrames = 0;
|
||||
this._lastUpdate = Date.now();
|
||||
this._deltaTime = 0.0;
|
||||
|
||||
// Scheduler for user registration update
|
||||
this._scheduler = null;
|
||||
// Scheduler for life-cycle methods in component
|
||||
this._compScheduler = null;
|
||||
// Node activator
|
||||
this._nodeActivator = null;
|
||||
// Action manager
|
||||
this._actionManager = null;
|
||||
|
||||
var self = this;
|
||||
cc.game.on(cc.game.EVENT_SHOW, function () {
|
||||
self._lastUpdate = Date.now();
|
||||
self._deltaTime = 0.0;
|
||||
|
||||
// Scheduler for user registration update
|
||||
self._scheduler = null;
|
||||
// Scheduler for life-cycle methods in component
|
||||
self._compScheduler = null;
|
||||
// Node activator
|
||||
self._nodeActivator = null;
|
||||
// Action manager
|
||||
self._actionManager = null;
|
||||
|
||||
cc.game.on(cc.game.EVENT_SHOW, function () {
|
||||
self._lastUpdate = Date.now();
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
cc.Director.prototype = {
|
||||
constructor: cc.Director,
|
||||
init: function () {
|
||||
this._oldAnimationInterval = this._animationInterval = 1.0 / cc.defaultFPS;
|
||||
|
||||
@@ -161,7 +162,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
/*
|
||||
* Manage all init process shared between the web engine and jsb engine.
|
||||
* All platform independent init process should be occupied here.
|
||||
*/
|
||||
@@ -836,7 +837,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
* @deprecated
|
||||
*/
|
||||
getRunningScene: function () {
|
||||
return null;
|
||||
return this._scene;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -989,7 +990,120 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
getPhysicsManager: function () {
|
||||
return this._physicsManager;
|
||||
},
|
||||
});
|
||||
|
||||
// Loop management
|
||||
/*
|
||||
* Starts Animation
|
||||
*/
|
||||
startAnimation: function () {
|
||||
this.invalid = false;
|
||||
this._lastUpdate = Date.now();
|
||||
},
|
||||
|
||||
/*
|
||||
* Stops animation
|
||||
*/
|
||||
stopAnimation: function () {
|
||||
this.invalid = true;
|
||||
},
|
||||
|
||||
/*
|
||||
* Run main loop of director
|
||||
*/
|
||||
mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) {
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
|
||||
this._compScheduler.startPhase();
|
||||
this._compScheduler.updatePhase(deltaTime);
|
||||
|
||||
if (updateAnimate) {
|
||||
this._scheduler.update(deltaTime);
|
||||
}
|
||||
|
||||
this._compScheduler.lateUpdatePhase(deltaTime);
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
}
|
||||
|
||||
this.emit(cc.Director.EVENT_BEFORE_VISIT);
|
||||
// update the scene
|
||||
this.emit(cc.Director.EVENT_AFTER_VISIT);
|
||||
|
||||
// Render
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
} : function () {
|
||||
if (this._purgeDirectorInNextLoop) {
|
||||
this._purgeDirectorInNextLoop = false;
|
||||
this.purgeDirector();
|
||||
}
|
||||
else if (!this.invalid) {
|
||||
// calculate "global" dt
|
||||
this.calculateDeltaTime();
|
||||
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Call start for new added components
|
||||
this._compScheduler.startPhase();
|
||||
// Update for components
|
||||
this._compScheduler.updatePhase(this._deltaTime);
|
||||
// Engine update with scheduler
|
||||
this._scheduler.update(this._deltaTime);
|
||||
// Late update for components
|
||||
this._compScheduler.lateUpdatePhase(this._deltaTime);
|
||||
// User can use this event to do things after update
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
}
|
||||
this.emit(cc.Director.EVENT_BEFORE_VISIT);
|
||||
// update the scene
|
||||
this.emit(cc.Director.EVENT_AFTER_VISIT);
|
||||
|
||||
// Render
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
eventManager.frameUpdateListeners();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets animation interval, this doesn't control the main loop.
|
||||
* To control the game's frame rate overall, please use {{#crossLink "Game.setFrameRate"}}cc.game.setFrameRate{{/crossLink}}
|
||||
* @method setAnimationInterval
|
||||
* @param {Number} value - The animation interval desired.
|
||||
*/
|
||||
setAnimationInterval: function (value) {
|
||||
this._animationInterval = value;
|
||||
if (!this.invalid) {
|
||||
this.stopAnimation();
|
||||
this.startAnimation();
|
||||
}
|
||||
},
|
||||
|
||||
__fastOn: function (type, callback, target) {
|
||||
var listeners = this._bubblingListeners;
|
||||
if (!listeners) {
|
||||
listeners = this._bubblingListeners = new EventListeners();
|
||||
}
|
||||
listeners.add(type, callback, target);
|
||||
this._addEventFlag(type, listeners, false);
|
||||
},
|
||||
|
||||
__fastOff: function (type, callback, target) {
|
||||
var listeners = this._bubblingListeners;
|
||||
if (listeners) {
|
||||
listeners.remove(type, callback, target);
|
||||
this._purgeEventFlag(type, listeners, false);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Event target
|
||||
cc.js.addon(cc.Director.prototype, EventTarget.prototype);
|
||||
@@ -1133,132 +1247,13 @@ cc.Director.EVENT_AFTER_VISIT = "director_after_visit";
|
||||
*/
|
||||
cc.Director.EVENT_AFTER_DRAW = "director_after_draw";
|
||||
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
||||
cc.DisplayLinkDirector = cc.Director.extend(/** @lends cc.Director# */{
|
||||
invalid: false,
|
||||
|
||||
/**
|
||||
* Starts Animation
|
||||
*/
|
||||
startAnimation: function () {
|
||||
this.invalid = false;
|
||||
this._lastUpdate = Date.now();
|
||||
},
|
||||
|
||||
/**
|
||||
* Run main loop of director
|
||||
*/
|
||||
mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) {
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
|
||||
this._compScheduler.startPhase();
|
||||
this._compScheduler.updatePhase(deltaTime);
|
||||
|
||||
if (updateAnimate) {
|
||||
this._scheduler.update(deltaTime);
|
||||
}
|
||||
|
||||
this._compScheduler.lateUpdatePhase(deltaTime);
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
}
|
||||
|
||||
this.emit(cc.Director.EVENT_BEFORE_VISIT);
|
||||
// update the scene
|
||||
this.emit(cc.Director.EVENT_AFTER_VISIT);
|
||||
|
||||
// Render
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
} : function () {
|
||||
if (this._purgeDirectorInNextLoop) {
|
||||
this._purgeDirectorInNextLoop = false;
|
||||
this.purgeDirector();
|
||||
}
|
||||
else if (!this.invalid) {
|
||||
// calculate "global" dt
|
||||
this.calculateDeltaTime();
|
||||
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Call start for new added components
|
||||
this._compScheduler.startPhase();
|
||||
// Update for components
|
||||
this._compScheduler.updatePhase(this._deltaTime);
|
||||
// Engine update with scheduler
|
||||
this._scheduler.update(this._deltaTime);
|
||||
// Late update for components
|
||||
this._compScheduler.lateUpdatePhase(this._deltaTime);
|
||||
// User can use this event to do things after update
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
}
|
||||
this.emit(cc.Director.EVENT_BEFORE_VISIT);
|
||||
// update the scene
|
||||
this.emit(cc.Director.EVENT_AFTER_VISIT);
|
||||
|
||||
// Render
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
eventManager.frameUpdateListeners();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops animation
|
||||
*/
|
||||
stopAnimation: function () {
|
||||
this.invalid = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets animation interval, this doesn't control the main loop.
|
||||
* To control the game's frame rate overall, please use {{#crossLink "Game.setFrameRate"}}cc.game.setFrameRate{{/crossLink}}
|
||||
* @param {Number} value - The animation interval desired.
|
||||
*/
|
||||
setAnimationInterval: function (value) {
|
||||
this._animationInterval = value;
|
||||
if (!this.invalid) {
|
||||
this.stopAnimation();
|
||||
this.startAnimation();
|
||||
}
|
||||
},
|
||||
|
||||
__fastOn: function (type, callback, target) {
|
||||
var listeners = this._bubblingListeners;
|
||||
if (!listeners) {
|
||||
listeners = this._bubblingListeners = new EventListeners();
|
||||
}
|
||||
listeners.add(type, callback, target);
|
||||
this._addEventFlag(type, listeners, false);
|
||||
},
|
||||
|
||||
__fastOff: function (type, callback, target) {
|
||||
var listeners = this._bubblingListeners;
|
||||
if (listeners) {
|
||||
listeners.remove(type, callback, target);
|
||||
this._purgeEventFlag(type, listeners, false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
cc.Director.sharedDirector = null;
|
||||
cc.Director.firstUseDirector = true;
|
||||
|
||||
cc.Director._getInstance = function () {
|
||||
if (cc.Director.firstUseDirector) {
|
||||
cc.Director.firstUseDirector = false;
|
||||
cc.Director.sharedDirector = new cc.DisplayLinkDirector();
|
||||
cc.Director.sharedDirector = new cc.Director();
|
||||
cc.Director.sharedDirector.init();
|
||||
}
|
||||
return cc.Director.sharedDirector;
|
||||
|
||||
+16
-16
@@ -280,23 +280,23 @@ var getTargetId = function (target) {
|
||||
*
|
||||
* @class Scheduler
|
||||
*/
|
||||
cc.Scheduler = cc._Class.extend({
|
||||
cc.Scheduler = function () {
|
||||
this._timeScale = 1.0;
|
||||
this._updatesNegList = []; // list of priority < 0
|
||||
this._updates0List = []; // list of priority == 0
|
||||
this._updatesPosList = []; // list of priority > 0
|
||||
this._hashForUpdates = {}; // hash used to fetch quickly the list entries for pause, delete, etc
|
||||
this._hashForTimers = {}; // Used for "selectors with interval"
|
||||
this._currentTarget = null;
|
||||
this._currentTargetSalvaged = false;
|
||||
this._updateHashLocked = false; // If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||
|
||||
ctor: function () {
|
||||
this._timeScale = 1.0;
|
||||
this._updatesNegList = []; // list of priority < 0
|
||||
this._updates0List = []; // list of priority == 0
|
||||
this._updatesPosList = []; // list of priority > 0
|
||||
this._hashForUpdates = {}; // hash used to fetch quickly the list entries for pause, delete, etc
|
||||
this._hashForTimers = {}; // Used for "selectors with interval"
|
||||
this._currentTarget = null;
|
||||
this._currentTargetSalvaged = false;
|
||||
this._updateHashLocked = false; // If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||
|
||||
this._arrayForTimers = []; // Speed up indexing
|
||||
//this._arrayForUpdates = []; // Speed up indexing
|
||||
},
|
||||
this._arrayForTimers = []; // Speed up indexing
|
||||
//this._arrayForUpdates = []; // Speed up indexing
|
||||
};
|
||||
|
||||
cc.Scheduler.prototype = {
|
||||
constructor: cc.Scheduler,
|
||||
//-----------------------private method----------------------
|
||||
|
||||
_removeHashElement: function (element) {
|
||||
@@ -1113,7 +1113,7 @@ cc.Scheduler = cc._Class.extend({
|
||||
//cc.log("unscheduleAllCallbacksWithMinPriority is deprecated. Please use unscheduleAllWithMinPriority.");
|
||||
this.unscheduleAllWithMinPriority(minPriority);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Priority level reserved for system services.
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
require('../label/CCHtmlTextParser');
|
||||
require('../label/CCTextUtils');
|
||||
|
||||
var utils = require('../utils/text-utils');
|
||||
var HtmlTextParser = utils.HtmlTextParser;
|
||||
var TextUtils = utils.TextUtils;
|
||||
var CustomFontLoader = utils.CustomFontLoader;
|
||||
|
||||
var JS = require("../platform/js");
|
||||
|
||||
@@ -31,7 +34,7 @@ var HorizontalAlign = cc.TextAlignment;
|
||||
var VerticalAlign = cc.VerticalTextAlignment;
|
||||
var RichTextChildName = "RICHTEXT_CHILD"
|
||||
var RichTextChildZIndex = - 1000000;
|
||||
|
||||
var _htmlTextParser = new HtmlTextParser();
|
||||
|
||||
// Returns a function, that, as long as it continues to be invoked, will not
|
||||
// be triggered. The function will be called after it stops being called for
|
||||
@@ -337,7 +340,7 @@ var RichText = cc.Class({
|
||||
self._updateRichText();
|
||||
};
|
||||
|
||||
cc.CustomFontLoader.loadTTF(rawUrl, callback);
|
||||
CustomFontLoader.loadTTF(rawUrl, callback);
|
||||
},
|
||||
|
||||
_measureText: function (styleIndex, string) {
|
||||
@@ -471,7 +474,7 @@ var RichText = cc.Class({
|
||||
}
|
||||
}
|
||||
if (fragmentWidth > this.maxWidth) {
|
||||
var fragments = cc.TextUtils.fragmentText(labelString,
|
||||
var fragments = TextUtils.fragmentText(labelString,
|
||||
fragmentWidth,
|
||||
this.maxWidth,
|
||||
this._measureText(styleIndex));
|
||||
@@ -616,7 +619,7 @@ var RichText = cc.Class({
|
||||
_updateRichText: function () {
|
||||
if (!this.enabled) return;
|
||||
|
||||
var newTextArray = cc.htmlTextParser.parse(this.string);
|
||||
var newTextArray = _htmlTextParser.parse(this.string);
|
||||
if (!this._needsUpdateTextLayout(newTextArray)) {
|
||||
this._textArray = newTextArray;
|
||||
this._updateLabelSegmentTextAttributes();
|
||||
@@ -701,16 +704,16 @@ var RichText = cc.Class({
|
||||
|
||||
_getFirstWordLen: function (text, startIndex, textLen) {
|
||||
var character = text.charAt(startIndex);
|
||||
if (cc.TextUtils.isUnicodeCJK(character)
|
||||
|| cc.TextUtils.isUnicodeSpace(character)) {
|
||||
if (TextUtils.isUnicodeCJK(character)
|
||||
|| TextUtils.isUnicodeSpace(character)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
var len = 1;
|
||||
for (var index = startIndex + 1; index < textLen; ++index) {
|
||||
character = text.charAt(index);
|
||||
if (cc.TextUtils.isUnicodeSpace(character)
|
||||
|| cc.TextUtils.isUnicodeCJK(character)) {
|
||||
if (TextUtils.isUnicodeSpace(character)
|
||||
|| TextUtils.isUnicodeCJK(character)) {
|
||||
break;
|
||||
}
|
||||
len++;
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var js = require('../platform/js');
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* <p>
|
||||
@@ -45,26 +48,21 @@
|
||||
* @param {Number} listenerID
|
||||
* @param {Number} callback
|
||||
*/
|
||||
cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
|
||||
/*
|
||||
* Initializes event with type and callback function.
|
||||
* @param {Number} type
|
||||
* @param {String} listenerID
|
||||
* @param {Function} callback
|
||||
*/
|
||||
ctor: function (type, listenerID, callback) {
|
||||
this._onEvent = callback; // Event callback function
|
||||
this._type = type || 0; // Event listener type
|
||||
this._listenerID = listenerID || ""; // Event listener ID
|
||||
this._registered = false; // Whether the listener has been added to dispatcher.
|
||||
cc.EventListener = function (type, listenerID, callback) {
|
||||
this._onEvent = callback; // Event callback function
|
||||
this._type = type || 0; // Event listener type
|
||||
this._listenerID = listenerID || ""; // Event listener ID
|
||||
this._registered = false; // Whether the listener has been added to dispatcher.
|
||||
|
||||
this._fixedPriority = 0; // The higher the number, the higher the priority, 0 is for scene graph base priority.
|
||||
this._node = null; // scene graph based priority
|
||||
this._target = null;
|
||||
this._paused = true; // Whether the listener is paused
|
||||
this._isEnabled = true; // Whether the listener is enabled
|
||||
},
|
||||
this._fixedPriority = 0; // The higher the number, the higher the priority, 0 is for scene graph base priority.
|
||||
this._node = null; // scene graph based priority
|
||||
this._target = null;
|
||||
this._paused = true; // Whether the listener is paused
|
||||
this._isEnabled = true; // Whether the listener is enabled
|
||||
};
|
||||
|
||||
cc.EventListener.prototype = {
|
||||
constructor: cc.EventListener,
|
||||
/*
|
||||
* <p>
|
||||
* Sets paused state for the listener
|
||||
@@ -243,7 +241,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
|
||||
*/
|
||||
release:function () {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// event listener type
|
||||
/**
|
||||
@@ -303,13 +301,22 @@ cc.EventListener.ACCELERATION = 6;
|
||||
*/
|
||||
cc.EventListener.CUSTOM = 8;
|
||||
|
||||
cc._EventListenerCustom = cc.EventListener.extend({
|
||||
_onCustomEvent: null,
|
||||
ctor: function (listenerId, callback) {
|
||||
this._onCustomEvent = callback;
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.CUSTOM, listenerId, this._callback);
|
||||
},
|
||||
var ListenerID = cc.EventListener.ListenerID = {
|
||||
MOUSE: '__cc_mouse',
|
||||
TOUCH_ONE_BY_ONE: '__cc_touch_one_by_one',
|
||||
TOUCH_ALL_AT_ONCE: '__cc_touch_all_at_once',
|
||||
KEYBOARD: '__cc_keyboard',
|
||||
ACCELERATION: '__cc_acceleration',
|
||||
};
|
||||
|
||||
var Custom = function (listenerId, callback) {
|
||||
this._onCustomEvent = callback;
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.CUSTOM, listenerId, this._callback);
|
||||
};
|
||||
js.extend(Custom, cc.EventListener);
|
||||
js.addon(Custom.prototype, {
|
||||
_onCustomEvent: null,
|
||||
|
||||
_callback: function (event) {
|
||||
if (this._onCustomEvent !== null)
|
||||
this._onCustomEvent(event);
|
||||
@@ -320,20 +327,20 @@ cc._EventListenerCustom = cc.EventListener.extend({
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
return new cc._EventListenerCustom(this._listenerID, this._onCustomEvent);
|
||||
return new Custom(this._listenerID, this._onCustomEvent);
|
||||
}
|
||||
});
|
||||
|
||||
cc._EventListenerMouse = cc.EventListener.extend({
|
||||
var Mouse = function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.MOUSE, ListenerID.MOUSE, this._callback);
|
||||
};
|
||||
js.extend(Mouse, cc.EventListener);
|
||||
js.addon(Mouse.prototype, {
|
||||
onMouseDown: null,
|
||||
onMouseUp: null,
|
||||
onMouseMove: null,
|
||||
onMouseScroll: null,
|
||||
|
||||
ctor: function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.MOUSE, cc._EventListenerMouse.LISTENER_ID, this._callback);
|
||||
},
|
||||
|
||||
_callback: function (event) {
|
||||
var eventType = cc.Event.EventMouse;
|
||||
switch (event._eventType) {
|
||||
@@ -359,7 +366,7 @@ cc._EventListenerMouse = cc.EventListener.extend({
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var eventListener = new cc._EventListenerMouse();
|
||||
var eventListener = new Mouse();
|
||||
eventListener.onMouseDown = this.onMouseDown;
|
||||
eventListener.onMouseUp = this.onMouseUp;
|
||||
eventListener.onMouseMove = this.onMouseMove;
|
||||
@@ -372,9 +379,13 @@ cc._EventListenerMouse = cc.EventListener.extend({
|
||||
}
|
||||
});
|
||||
|
||||
cc._EventListenerMouse.LISTENER_ID = "__cc_mouse";
|
||||
|
||||
cc._EventListenerTouchOneByOne = cc.EventListener.extend({
|
||||
var TouchOneByOne = function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ONE_BY_ONE, ListenerID.TOUCH_ONE_BY_ONE, null);
|
||||
this._claimedTouches = [];
|
||||
};
|
||||
js.extend(TouchOneByOne, cc.EventListener);
|
||||
js.addon(TouchOneByOne.prototype, {
|
||||
constructor: TouchOneByOne,
|
||||
_claimedTouches: null,
|
||||
swallowTouches: false,
|
||||
onTouchBegan: null,
|
||||
@@ -382,11 +393,6 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({
|
||||
onTouchEnded: null,
|
||||
onTouchCancelled: null,
|
||||
|
||||
ctor: function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ONE_BY_ONE, cc._EventListenerTouchOneByOne.LISTENER_ID, null);
|
||||
this._claimedTouches = [];
|
||||
},
|
||||
|
||||
setSwallowTouches: function (needSwallow) {
|
||||
this.swallowTouches = needSwallow;
|
||||
},
|
||||
@@ -396,7 +402,7 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var eventListener = new cc._EventListenerTouchOneByOne();
|
||||
var eventListener = new TouchOneByOne();
|
||||
eventListener.onTouchBegan = this.onTouchBegan;
|
||||
eventListener.onTouchMoved = this.onTouchMoved;
|
||||
eventListener.onTouchEnded = this.onTouchEnded;
|
||||
@@ -414,20 +420,19 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({
|
||||
}
|
||||
});
|
||||
|
||||
cc._EventListenerTouchOneByOne.LISTENER_ID = "__cc_touch_one_by_one";
|
||||
|
||||
cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({
|
||||
var TouchAllAtOnce = function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ALL_AT_ONCE, ListenerID.TOUCH_ALL_AT_ONCE, null);
|
||||
};
|
||||
js.extend(TouchAllAtOnce, cc.EventListener);
|
||||
js.addon(TouchAllAtOnce.prototype, {
|
||||
constructor: TouchAllAtOnce,
|
||||
onTouchesBegan: null,
|
||||
onTouchesMoved: null,
|
||||
onTouchesEnded: null,
|
||||
onTouchesCancelled: null,
|
||||
|
||||
ctor: function(){
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ALL_AT_ONCE, cc._EventListenerTouchAllAtOnce.LISTENER_ID, null);
|
||||
},
|
||||
|
||||
clone: function(){
|
||||
var eventListener = new cc._EventListenerTouchAllAtOnce();
|
||||
var eventListener = new TouchAllAtOnce();
|
||||
eventListener.onTouchesBegan = this.onTouchesBegan;
|
||||
eventListener.onTouchesMoved = this.onTouchesMoved;
|
||||
eventListener.onTouchesEnded = this.onTouchesEnded;
|
||||
@@ -445,62 +450,16 @@ cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({
|
||||
}
|
||||
});
|
||||
|
||||
cc._EventListenerTouchAllAtOnce.LISTENER_ID = "__cc_touch_all_at_once";
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Create a EventListener object with configuration including the event type, handlers and other parameters.
|
||||
* In handlers, this refer to the event listener object itself.
|
||||
* You can also pass custom parameters in the configuration object,
|
||||
* all custom parameters will be polyfilled into the event listener object and can be accessed in handlers.
|
||||
* !#zh 通过指定不同的 Event 对象来设置想要创建的事件监听器。
|
||||
* @method create
|
||||
* @param {Object} argObj a json object
|
||||
* @returns {EventListener}
|
||||
* @static
|
||||
* @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventListener/create.js}
|
||||
*/
|
||||
cc.EventListener.create = function(argObj){
|
||||
|
||||
cc.assertID(argObj&&argObj.event, 1900);
|
||||
|
||||
var listenerType = argObj.event;
|
||||
delete argObj.event;
|
||||
|
||||
var listener = null;
|
||||
if(listenerType === cc.EventListener.TOUCH_ONE_BY_ONE)
|
||||
listener = new cc._EventListenerTouchOneByOne();
|
||||
else if(listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE)
|
||||
listener = new cc._EventListenerTouchAllAtOnce();
|
||||
else if(listenerType === cc.EventListener.MOUSE)
|
||||
listener = new cc._EventListenerMouse();
|
||||
else if(listenerType === cc.EventListener.CUSTOM){
|
||||
listener = new cc._EventListenerCustom(argObj.eventName, argObj.callback);
|
||||
delete argObj.eventName;
|
||||
delete argObj.callback;
|
||||
} else if(listenerType === cc.EventListener.KEYBOARD)
|
||||
listener = new cc._EventListenerKeyboard();
|
||||
else if(listenerType === cc.EventListener.ACCELERATION){
|
||||
listener = new cc._EventListenerAcceleration(argObj.callback);
|
||||
delete argObj.callback;
|
||||
}
|
||||
|
||||
for(var key in argObj) {
|
||||
listener[key] = argObj[key];
|
||||
}
|
||||
|
||||
return listener;
|
||||
};
|
||||
|
||||
//Acceleration
|
||||
cc._EventListenerAcceleration = cc.EventListener.extend({
|
||||
var Acceleration = function (callback) {
|
||||
this._onAccelerationEvent = callback;
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.ACCELERATION, ListenerID.ACCELERATION, this._callback);
|
||||
};
|
||||
js.extend(Acceleration, cc.EventListener);
|
||||
js.addon(Acceleration.prototype, {
|
||||
constructor: Acceleration,
|
||||
_onAccelerationEvent: null,
|
||||
|
||||
ctor: function (callback) {
|
||||
this._onAccelerationEvent = callback;
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.ACCELERATION, cc._EventListenerAcceleration.LISTENER_ID, this._callback);
|
||||
},
|
||||
|
||||
_callback: function (event) {
|
||||
this._onAccelerationEvent(event.acc, event);
|
||||
},
|
||||
@@ -512,22 +471,21 @@ cc._EventListenerAcceleration = cc.EventListener.extend({
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
return new cc._EventListenerAcceleration(this._onAccelerationEvent);
|
||||
return new Acceleration(this._onAccelerationEvent);
|
||||
}
|
||||
});
|
||||
|
||||
cc._EventListenerAcceleration.LISTENER_ID = "__cc_acceleration";
|
||||
|
||||
|
||||
//Keyboard
|
||||
cc._EventListenerKeyboard = cc.EventListener.extend({
|
||||
var Keyboard = function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.KEYBOARD, ListenerID.KEYBOARD, this._callback);
|
||||
};
|
||||
js.extend(Keyboard, cc.EventListener);
|
||||
js.addon(Keyboard.prototype, {
|
||||
constructor: Keyboard,
|
||||
onKeyPressed: null,
|
||||
onKeyReleased: null,
|
||||
|
||||
ctor: function () {
|
||||
cc.EventListener.prototype.ctor.call(this, cc.EventListener.KEYBOARD, cc._EventListenerKeyboard.LISTENER_ID, this._callback);
|
||||
},
|
||||
|
||||
_callback: function (event) {
|
||||
if (event.isPressed) {
|
||||
if (this.onKeyPressed)
|
||||
@@ -539,7 +497,7 @@ cc._EventListenerKeyboard = cc.EventListener.extend({
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var eventListener = new cc._EventListenerKeyboard();
|
||||
var eventListener = new Keyboard();
|
||||
eventListener.onKeyPressed = this.onKeyPressed;
|
||||
eventListener.onKeyReleased = this.onKeyReleased;
|
||||
return eventListener;
|
||||
@@ -554,4 +512,47 @@ cc._EventListenerKeyboard = cc.EventListener.extend({
|
||||
}
|
||||
});
|
||||
|
||||
cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard";
|
||||
/**
|
||||
* !#en
|
||||
* Create a EventListener object with configuration including the event type, handlers and other parameters.
|
||||
* In handlers, this refer to the event listener object itself.
|
||||
* You can also pass custom parameters in the configuration object,
|
||||
* all custom parameters will be polyfilled into the event listener object and can be accessed in handlers.
|
||||
* !#zh 通过指定不同的 Event 对象来设置想要创建的事件监听器。
|
||||
* @method create
|
||||
* @param {Object} argObj a json object
|
||||
* @returns {EventListener}
|
||||
* @static
|
||||
* @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventListener/create.js}
|
||||
*/
|
||||
cc.EventListener.create = function (argObj) {
|
||||
cc.assertID(argObj&&argObj.event, 1900);
|
||||
|
||||
var listenerType = argObj.event;
|
||||
delete argObj.event;
|
||||
|
||||
var listener = null;
|
||||
if(listenerType === cc.EventListener.TOUCH_ONE_BY_ONE)
|
||||
listener = new TouchOneByOne();
|
||||
else if(listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE)
|
||||
listener = new TouchAllAtOnce();
|
||||
else if(listenerType === cc.EventListener.MOUSE)
|
||||
listener = new Mouse();
|
||||
else if(listenerType === cc.EventListener.CUSTOM){
|
||||
listener = new Custom(argObj.eventName, argObj.callback);
|
||||
delete argObj.eventName;
|
||||
delete argObj.callback;
|
||||
} else if(listenerType === cc.EventListener.KEYBOARD)
|
||||
listener = new Keyboard();
|
||||
else if(listenerType === cc.EventListener.ACCELERATION){
|
||||
listener = new Acceleration(argObj.callback);
|
||||
delete argObj.callback;
|
||||
}
|
||||
|
||||
for(var key in argObj) {
|
||||
listener[key] = argObj[key];
|
||||
}
|
||||
return listener;
|
||||
};
|
||||
|
||||
module.exports = cc.EventListener;
|
||||
@@ -23,15 +23,16 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var js = require('../platform/js');
|
||||
require('./CCEventListener');
|
||||
var ListenerID = cc.EventListener.ListenerID;
|
||||
|
||||
var _EventListenerVector = cc._Class.extend({
|
||||
|
||||
ctor: function () {
|
||||
this._fixedListeners = [];
|
||||
this._sceneGraphListeners = [];
|
||||
this.gt0Index = 0;
|
||||
},
|
||||
|
||||
var _EventListenerVector = function () {
|
||||
this._fixedListeners = [];
|
||||
this._sceneGraphListeners = [];
|
||||
this.gt0Index = 0;
|
||||
};
|
||||
_EventListenerVector.prototype = {
|
||||
constructor: _EventListenerVector,
|
||||
size: function () {
|
||||
return this._fixedListeners.length + this._sceneGraphListeners.length;
|
||||
},
|
||||
@@ -67,16 +68,16 @@ var _EventListenerVector = cc._Class.extend({
|
||||
getSceneGraphPriorityListeners: function () {
|
||||
return this._sceneGraphListeners;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var __getListenerID = function (event) {
|
||||
var eventType = cc.Event, type = event.type;
|
||||
if (type === eventType.ACCELERATION)
|
||||
return cc._EventListenerAcceleration.LISTENER_ID;
|
||||
return ListenerID.ACCELERATION;
|
||||
if (type === eventType.KEYBOARD)
|
||||
return cc._EventListenerKeyboard.LISTENER_ID;
|
||||
return ListenerID.KEYBOARD;
|
||||
if (type.startsWith(eventType.MOUSE))
|
||||
return cc._EventListenerMouse.LISTENER_ID;
|
||||
return ListenerID.MOUSE;
|
||||
if (type.startsWith(eventType.TOUCH)){
|
||||
// Touch listener is very special, it contains two kinds of listeners, EventListenerTouchOneByOne and EventListenerTouchAllAtOnce.
|
||||
// return UNKNOWN instead.
|
||||
@@ -428,11 +429,11 @@ var eventManager = {
|
||||
return;
|
||||
|
||||
var listeners;
|
||||
listeners = this._listenersMap[cc._EventListenerTouchOneByOne.LISTENER_ID];
|
||||
listeners = this._listenersMap[ListenerID.TOUCH_ONE_BY_ONE];
|
||||
if (listeners) {
|
||||
this._onUpdateListeners(listeners);
|
||||
}
|
||||
listeners = this._listenersMap[cc._EventListenerTouchAllAtOnce.LISTENER_ID];
|
||||
listeners = this._listenersMap[ListenerID.TOUCH_ALL_AT_ONCE];
|
||||
if (listeners) {
|
||||
this._onUpdateListeners(listeners);
|
||||
}
|
||||
@@ -528,11 +529,11 @@ var eventManager = {
|
||||
},
|
||||
|
||||
_dispatchTouchEvent: function (event) {
|
||||
this._sortEventListeners(cc._EventListenerTouchOneByOne.LISTENER_ID);
|
||||
this._sortEventListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
|
||||
this._sortEventListeners(ListenerID.TOUCH_ONE_BY_ONE);
|
||||
this._sortEventListeners(ListenerID.TOUCH_ALL_AT_ONCE);
|
||||
|
||||
var oneByOneListeners = this._getListeners(cc._EventListenerTouchOneByOne.LISTENER_ID);
|
||||
var allAtOnceListeners = this._getListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
|
||||
var oneByOneListeners = this._getListeners(ListenerID.TOUCH_ONE_BY_ONE);
|
||||
var allAtOnceListeners = this._getListeners(ListenerID.TOUCH_ALL_AT_ONCE);
|
||||
|
||||
// If there aren't any touch listeners, return directly.
|
||||
if (null === oneByOneListeners && null === allAtOnceListeners)
|
||||
@@ -785,7 +786,11 @@ var eventManager = {
|
||||
* @return {EventListener} the generated event. Needed in order to remove the event from the dispatcher
|
||||
*/
|
||||
addCustomListener: function (eventName, callback) {
|
||||
var listener = new cc._EventListenerCustom(eventName, callback);
|
||||
var listener = new cc.EventListener.create({
|
||||
event: cc.EventListener.CUSTOM,
|
||||
eventName: eventName,
|
||||
callback: callback
|
||||
});
|
||||
this.addListener(listener, 1);
|
||||
return listener;
|
||||
},
|
||||
@@ -944,15 +949,15 @@ var eventManager = {
|
||||
}
|
||||
} else {
|
||||
if (listenerType === cc.EventListener.TOUCH_ONE_BY_ONE)
|
||||
_t._removeListenersForListenerID(cc._EventListenerTouchOneByOne.LISTENER_ID);
|
||||
_t._removeListenersForListenerID(ListenerID.TOUCH_ONE_BY_ONE);
|
||||
else if (listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE)
|
||||
_t._removeListenersForListenerID(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
|
||||
_t._removeListenersForListenerID(ListenerID.TOUCH_ALL_AT_ONCE);
|
||||
else if (listenerType === cc.EventListener.MOUSE)
|
||||
_t._removeListenersForListenerID(cc._EventListenerMouse.LISTENER_ID);
|
||||
_t._removeListenersForListenerID(ListenerID.MOUSE);
|
||||
else if (listenerType === cc.EventListener.ACCELERATION)
|
||||
_t._removeListenersForListenerID(cc._EventListenerAcceleration.LISTENER_ID);
|
||||
_t._removeListenersForListenerID(ListenerID.ACCELERATION);
|
||||
else if (listenerType === cc.EventListener.KEYBOARD)
|
||||
_t._removeListenersForListenerID(cc._EventListenerKeyboard.LISTENER_ID);
|
||||
_t._removeListenersForListenerID(ListenerID.KEYBOARD);
|
||||
else
|
||||
cc.logID(3501);
|
||||
}
|
||||
|
||||
@@ -32,13 +32,12 @@
|
||||
* @param {Number} y
|
||||
* @param {Number} id
|
||||
*/
|
||||
cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
|
||||
|
||||
ctor:function (x, y, id) {
|
||||
this._lastModified = 0;
|
||||
this.setTouchInfo(id, x, y);
|
||||
},
|
||||
|
||||
cc.Touch = function (x, y, id) {
|
||||
this._lastModified = 0;
|
||||
this.setTouchInfo(id, x, y);
|
||||
};
|
||||
cc.Touch.prototype = {
|
||||
constructor: cc.Touch,
|
||||
/**
|
||||
* !#en Returns the current touch location in OpenGL coordinates.、
|
||||
* !#zh 获取当前触点位置。
|
||||
@@ -180,4 +179,4 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
|
||||
else
|
||||
this._prevPoint = cc.p(x || 0, y || 0);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -132,7 +132,7 @@ var SystemEvent = cc.Class({
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!eventManager.hasEventListener(cc._EventListenerKeyboard.LISTENER_ID)) {
|
||||
if (!eventManager.hasEventListener(cc.EventListener.ListenerID.KEYBOARD)) {
|
||||
var currentFrame = cc.director.getTotalFrames();
|
||||
if (currentFrame !== keyboardListenerAddFrame) {
|
||||
eventManager.addListener(keyboardListener, 1);
|
||||
@@ -155,7 +155,7 @@ var SystemEvent = cc.Class({
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!eventManager.hasEventListener(cc._EventListenerAcceleration.LISTENER_ID)) {
|
||||
if (!eventManager.hasEventListener(cc.EventListener.ListenerID.ACCELERATION)) {
|
||||
eventManager.addListener(accelerationListener, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Path = require('../utils/CCPath');
|
||||
require('../utils/CCPath');
|
||||
var Pipeline = require('./pipeline');
|
||||
var LoadingItems = require('./loading-items');
|
||||
|
||||
@@ -52,7 +52,7 @@ AssetLoader.prototype.handle = function (item, callback) {
|
||||
item.url = item.rawUrl = url;
|
||||
item.isRawAsset = isRawAsset;
|
||||
if (isRawAsset) {
|
||||
var ext = Path.extname(url).toLowerCase();
|
||||
var ext = cc.path.extname(url).toLowerCase();
|
||||
if (!ext) {
|
||||
callback(new Error(cc._getError(4931, uuid, url)));
|
||||
return;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Path = require('../utils/CCPath');
|
||||
var sys = require('../platform/CCSys');
|
||||
var Pipeline = require('./pipeline');
|
||||
var audioEngine = require('../../audio/CCAudioEngine');
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
var JS = require('../platform/js');
|
||||
var sys = require('../platform/CCSys');
|
||||
var Path = require('../utils/CCPath');
|
||||
require('../utils/CCPath');
|
||||
var Pipeline = require('./pipeline');
|
||||
var PackDownloader = require('./pack-downloader');
|
||||
// var downloadBinary = require('./binary-downloader');
|
||||
@@ -143,7 +143,7 @@ function _loadFont (name, srcs, type){
|
||||
if (srcs instanceof Array) {
|
||||
for (var i = 0, li = srcs.length; i < li; i++) {
|
||||
var src = srcs[i];
|
||||
type = Path.extname(src).toLowerCase();
|
||||
type = cc.path.extname(src).toLowerCase();
|
||||
fontStr += 'url(\'' + srcs[i] + '\') format(\'' + FONT_TYPE[type] + '\')';
|
||||
fontStr += (i === li - 1) ? ';' : ',';
|
||||
}
|
||||
@@ -174,8 +174,8 @@ function downloadFont (item, callback) {
|
||||
}
|
||||
_loadFont(name, srcs);
|
||||
} else {
|
||||
type = Path.extname(url);
|
||||
name = Path.basename(url, type);
|
||||
type = cc.path.extname(url);
|
||||
name = cc.path.basename(url, type);
|
||||
_loadFont(name, url, type);
|
||||
}
|
||||
if (document.fonts) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
var CallbacksInvoker = require('../platform/callbacks-invoker');
|
||||
var Path = require('../utils/CCPath');
|
||||
require('../utils/CCPath');
|
||||
var JS = require('../platform/js');
|
||||
|
||||
var _qid = (0|(Math.random()*998));
|
||||
@@ -86,7 +86,7 @@ function createItem (id, queueId) {
|
||||
}
|
||||
result.rawUrl = result.url;
|
||||
if (url && !result.type) {
|
||||
result.type = Path.extname(url).toLowerCase().substr(1);
|
||||
result.type = cc.path.extname(url).toLowerCase().substr(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1268,6 +1268,18 @@ function parseAttributes (cls, attrs, className, propName, usedInGetter) {
|
||||
|
||||
cc.Class = CCClass;
|
||||
|
||||
// Merged from old _CCClass
|
||||
|
||||
/**
|
||||
* ClassManager
|
||||
*/
|
||||
cc.ClassManager = {
|
||||
instanceId: (0 | (Math.random() * 998)),
|
||||
getNewInstanceId: function () {
|
||||
return this.instanceId++;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isArray: function (defaultVal) {
|
||||
defaultVal = getDefault(defaultVal);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
if (!cc.ClassManager) {
|
||||
require("./_CCClass");
|
||||
require("./CCClass");
|
||||
}
|
||||
|
||||
var eventManager = require('../event-manager');
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('./_CCClass');
|
||||
const js = require('./js');
|
||||
|
||||
/**
|
||||
* !#en Key map for keyboard event
|
||||
@@ -1143,19 +1143,6 @@ cc.getImageFormatByData = function (imgData) {
|
||||
* @type {Object}
|
||||
*/
|
||||
cc.macro = {
|
||||
/**
|
||||
* @property INVALID_INDEX
|
||||
* @type {Number}
|
||||
*/
|
||||
INVALID_INDEX: -1,
|
||||
|
||||
/**
|
||||
* Default Node tag
|
||||
* @property NODE_TAG_INVALID
|
||||
* @type {Number}
|
||||
*/
|
||||
NODE_TAG_INVALID: -1,
|
||||
|
||||
/**
|
||||
* PI is the ratio of a circle's circumference to its diameter.
|
||||
* @property PI
|
||||
@@ -1296,21 +1283,6 @@ cc.macro = {
|
||||
*/
|
||||
ONE_MINUS_CONSTANT_COLOR: 0x8002,
|
||||
|
||||
/**
|
||||
* the constant variable equals gl.LINEAR for texture
|
||||
* @property LINEAR
|
||||
* @type {Number}
|
||||
*/
|
||||
LINEAR: 0x2601,
|
||||
|
||||
/**
|
||||
* default gl blend dst function. Compatible with premultiplied alpha images.
|
||||
* @property BLEND_DST
|
||||
* @type {Number}
|
||||
*/
|
||||
BLEND_DST: 0x0303,
|
||||
|
||||
|
||||
//Possible device orientations
|
||||
|
||||
/**
|
||||
@@ -1362,52 +1334,11 @@ cc.macro = {
|
||||
*/
|
||||
ORIENTATION_AUTO: 3,
|
||||
|
||||
|
||||
DENSITYDPI_DEVICE: 'device-dpi',
|
||||
DENSITYDPI_HIGH: 'high-dpi',
|
||||
DENSITYDPI_MEDIUM: 'medium-dpi',
|
||||
DENSITYDPI_LOW: 'low-dpi',
|
||||
|
||||
/**
|
||||
* default size for font size
|
||||
* @property ITEM_SIZE
|
||||
* @type {Number}
|
||||
*/
|
||||
ITEM_SIZE: 32,
|
||||
|
||||
/**
|
||||
* default tag for current item
|
||||
* @property CURRENT_ITEM
|
||||
* @type {Number}
|
||||
*/
|
||||
CURRENT_ITEM: 0xc0c05001,
|
||||
/**
|
||||
* default tag for zoom action tag
|
||||
* @property ZOOM_ACTION_TAG
|
||||
* @type {Number}
|
||||
*/
|
||||
ZOOM_ACTION_TAG: 0xc0c05002,
|
||||
/**
|
||||
* default tag for normal
|
||||
* @property NORMAL_TAG
|
||||
* @type {Number}
|
||||
*/
|
||||
NORMAL_TAG: 8801,
|
||||
|
||||
/**
|
||||
* default selected tag
|
||||
* @property SELECTED_TAG
|
||||
* @type {Number}
|
||||
*/
|
||||
SELECTED_TAG: 8802,
|
||||
|
||||
/**
|
||||
* default disabled tag
|
||||
* @property DISABLE_TAG
|
||||
* @type {Number}
|
||||
*/
|
||||
DISABLE_TAG: 8803,
|
||||
|
||||
// General configurations
|
||||
/**
|
||||
* <p>
|
||||
@@ -1460,62 +1391,6 @@ cc.macro = {
|
||||
*/
|
||||
DIRECTOR_STATS_POSITION: cc.p(0, 0),
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Seconds between FPS updates.<br/>
|
||||
* 0.5 seconds, means that the FPS number will be updated every 0.5 seconds.<br/>
|
||||
* Having a bigger number means a more reliable FPS<br/>
|
||||
* <br/>
|
||||
* Default value: 0.1f<br/>
|
||||
* To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
|
||||
* </p>
|
||||
* @property {Number} DIRECTOR_FPS_INTERVAL
|
||||
*/
|
||||
DIRECTOR_FPS_INTERVAL: 0.5,
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* If enabled, the ccsg.Node objects (_ccsg.Sprite, _ccsg.Label,etc) will be able to render in subpixels.<br/>
|
||||
* If disabled, integer pixels will be used.<br/>
|
||||
* <br/>
|
||||
* To enable set it to 1. Enabled by default.<br/>
|
||||
* To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
|
||||
* </p>
|
||||
* @property {Number} COCOSNODE_RENDER_SUBPIXEL
|
||||
*/
|
||||
COCOSNODE_RENDER_SUBPIXEL: true,
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* If enabled, the _ccsg.Sprite objects rendered with cc.SpriteBatchNode will be able to render in subpixels.<br/>
|
||||
* If disabled, integer pixels will be used.<br/>
|
||||
* <br/>
|
||||
* To enable set it to 1. Enabled by default.<br/>
|
||||
* To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
|
||||
* </p>
|
||||
* @property {Number} SPRITEBATCHNODE_RENDER_SUBPIXEL
|
||||
*/
|
||||
SPRITEBATCHNODE_RENDER_SUBPIXEL: true,
|
||||
|
||||
/**
|
||||
* Automatically premultiply alpha for remote PNG resources.
|
||||
* @property {Boolean} AUTO_PREMULTIPLIED_ALPHA_FOR_PNG
|
||||
* @default false
|
||||
*/
|
||||
AUTO_PREMULTIPLIED_ALPHA_FOR_PNG: false,
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* If most of your images have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).<br/>
|
||||
* Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images)<br/>
|
||||
* <br/>
|
||||
* To enable set it to a value different than 0. Enabled by default.<br/>
|
||||
* To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
|
||||
* </p>
|
||||
* @property {Number} OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
|
||||
*/
|
||||
OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA: false,
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* If enabled, actions that alter the position property (eg: CCMoveBy, CCJumpBy, CCBezierBy, etc..) will be stacked. <br/>
|
||||
@@ -1635,7 +1510,7 @@ cc.macro = {
|
||||
* @default true
|
||||
*/
|
||||
var ENABLE_CULLING = true;
|
||||
cc.defineGetterSetter(cc.macro, 'ENABLE_CULLING',
|
||||
js.getset(cc.macro, 'ENABLE_CULLING',
|
||||
function () {
|
||||
return ENABLE_CULLING;
|
||||
},
|
||||
@@ -1656,24 +1531,6 @@ cc.defineGetterSetter(cc.macro, 'ENABLE_CULLING',
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* default gl blend src function. Compatible with premultiplied alpha images.
|
||||
* !#zh
|
||||
* 默认的混合源模式
|
||||
* @property BLEND_SRC
|
||||
* @type {Number}
|
||||
*/
|
||||
cc.defineGetterSetter(cc.macro, "BLEND_SRC", function (){
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL
|
||||
&& cc.macro.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) {
|
||||
return cc.macro.ONE;
|
||||
}
|
||||
else {
|
||||
return cc.macro.SRC_ALPHA;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
@@ -1737,69 +1594,4 @@ cc.radiansToDegrees = function (angle) {
|
||||
return angle * cc.macro.DEG;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
|
||||
* @param {Node} node setup node
|
||||
* @method nodeDrawSetup
|
||||
*/
|
||||
cc.nodeDrawSetup = function (node) {
|
||||
//cc.gl.enable(node._glServerState);
|
||||
if (node._shaderProgram) {
|
||||
//cc._renderContext.useProgram(node._shaderProgram._programObj);
|
||||
node._shaderProgram.use();
|
||||
node._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* <p>
|
||||
* GL states that are enabled:<br/>
|
||||
* - GL_TEXTURE_2D<br/>
|
||||
* - GL_VERTEX_ARRAY<br/>
|
||||
* - GL_TEXTURE_COORD_ARRAY<br/>
|
||||
* - GL_COLOR_ARRAY<br/>
|
||||
* </p>
|
||||
* @method enableDefaultGLStates
|
||||
*/
|
||||
// cc.enableDefaultGLStates = function () {
|
||||
//TODO OPENGL STUFF
|
||||
/*
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);*/
|
||||
// };
|
||||
|
||||
/*
|
||||
* <p>
|
||||
* Disable default GL states:<br/>
|
||||
* - GL_TEXTURE_2D<br/>
|
||||
* - GL_TEXTURE_COORD_ARRAY<br/>
|
||||
* - GL_COLOR_ARRAY<br/>
|
||||
* </p>
|
||||
* @method disableDefaultGLStates
|
||||
*/
|
||||
// cc.disableDefaultGLStates = function () {
|
||||
//TODO OPENGL
|
||||
/*
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
*/
|
||||
// };
|
||||
|
||||
/**
|
||||
* Check webgl error.Error will be shown in console if exists.
|
||||
* @method checkGLErrorDebug
|
||||
*/
|
||||
cc.checkGLErrorDebug = function () {
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
|
||||
var _error = cc._renderContext.getError();
|
||||
if (_error) {
|
||||
cc.logID(2400, _error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = cc.macro;
|
||||
|
||||
@@ -24,24 +24,23 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var js = require('../platform/js');
|
||||
|
||||
/**
|
||||
* A SAX Parser
|
||||
* @class saxParser
|
||||
*/
|
||||
cc.SAXParser = cc._Class.extend(/** @lends cc.saxParser# */{
|
||||
/**
|
||||
* Constructor of cc.SAXParser
|
||||
*/
|
||||
ctor: function () {
|
||||
if (window.DOMParser) {
|
||||
this._isSupportDOMParser = true;
|
||||
this._parser = new DOMParser();
|
||||
} else {
|
||||
this._isSupportDOMParser = false;
|
||||
this._parser = null;
|
||||
}
|
||||
},
|
||||
|
||||
cc.SAXParser = function () {
|
||||
if (window.DOMParser) {
|
||||
this._isSupportDOMParser = true;
|
||||
this._parser = new DOMParser();
|
||||
} else {
|
||||
this._isSupportDOMParser = false;
|
||||
this._parser = null;
|
||||
}
|
||||
};
|
||||
cc.SAXParser.prototype = {
|
||||
constructor: cc.SAXParser,
|
||||
/**
|
||||
* @method parse
|
||||
* @param {String} xmlTxt
|
||||
@@ -64,8 +63,7 @@ cc.SAXParser = cc._Class.extend(/** @lends cc.saxParser# */{
|
||||
}
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -73,8 +71,9 @@ cc.SAXParser = cc._Class.extend(/** @lends cc.saxParser# */{
|
||||
* @class plistParser
|
||||
* @extends SAXParser
|
||||
*/
|
||||
cc.PlistParser = cc.SAXParser.extend(/** @lends cc.plistParser# */{
|
||||
|
||||
cc.PlistParser = function () {};
|
||||
js.extend(cc.PlistParser, cc.SAXParser);
|
||||
js.addon(cc.PlistParser.prototype, {
|
||||
/**
|
||||
* parse a xml string as plist object.
|
||||
* @param {String} xmlTxt - plist xml contents
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var eventManager = require('../event-manager');
|
||||
|
||||
const eventManager = require('../event-manager');
|
||||
const js = require('../platform/js');
|
||||
const renderer = require('../renderer');
|
||||
require('../platform/CCClass');
|
||||
|
||||
function isWeChatGame () {
|
||||
return window['wx'];
|
||||
@@ -112,70 +114,68 @@ var _scissorRect = null;
|
||||
*
|
||||
* @class View
|
||||
*/
|
||||
var View = cc._Class.extend({
|
||||
/**
|
||||
* Constructor of View
|
||||
*/
|
||||
ctor: function () {
|
||||
var _t = this, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy;
|
||||
var View = function () {
|
||||
var _t = this, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy;
|
||||
|
||||
__BrowserGetter.init(this);
|
||||
__BrowserGetter.init(this);
|
||||
|
||||
// Size of parent node that contains cc.container and cc.game.canvas
|
||||
_t._frameSize = cc.size(0, 0);
|
||||
_t._initFrameSize();
|
||||
// Size of parent node that contains cc.container and cc.game.canvas
|
||||
_t._frameSize = cc.size(0, 0);
|
||||
_t._initFrameSize();
|
||||
|
||||
var w = cc.game.canvas.width, h = cc.game.canvas.height;
|
||||
// resolution size, it is the size appropriate for the app resources.
|
||||
_t._designResolutionSize = cc.size(w, h);
|
||||
_t._originalDesignResolutionSize = cc.size(w, h);
|
||||
// Viewport is the container's rect related to content's coordinates in pixel
|
||||
_t._viewPortRect = cc.rect(0, 0, w, h);
|
||||
// The visible rect in content's coordinate in point
|
||||
_t._visibleRect = cc.rect(0, 0, w, h);
|
||||
_t._contentTranslateLeftTop = {left: 0, top: 0};
|
||||
_t._autoFullScreen = false;
|
||||
// The device's pixel ratio (for retina displays)
|
||||
_t._devicePixelRatio = 1;
|
||||
// the view name
|
||||
_t._viewName = "Cocos2dHTML5";
|
||||
// Custom callback for resize event
|
||||
_t._resizeCallback = null;
|
||||
_t._orientationChanging = true;
|
||||
_t._resizing = false;
|
||||
var w = cc.game.canvas.width, h = cc.game.canvas.height;
|
||||
// resolution size, it is the size appropriate for the app resources.
|
||||
_t._designResolutionSize = cc.size(w, h);
|
||||
_t._originalDesignResolutionSize = cc.size(w, h);
|
||||
// Viewport is the container's rect related to content's coordinates in pixel
|
||||
_t._viewPortRect = cc.rect(0, 0, w, h);
|
||||
// The visible rect in content's coordinate in point
|
||||
_t._visibleRect = cc.rect(0, 0, w, h);
|
||||
_t._contentTranslateLeftTop = {left: 0, top: 0};
|
||||
_t._autoFullScreen = false;
|
||||
// The device's pixel ratio (for retina displays)
|
||||
_t._devicePixelRatio = 1;
|
||||
// the view name
|
||||
_t._viewName = "Cocos2dHTML5";
|
||||
// Custom callback for resize event
|
||||
_t._resizeCallback = null;
|
||||
_t._orientationChanging = true;
|
||||
_t._resizing = false;
|
||||
|
||||
_t._scaleX = 1;
|
||||
_t._originalScaleX = 1;
|
||||
_t._scaleY = 1;
|
||||
_t._originalScaleY = 1;
|
||||
_t._scaleX = 1;
|
||||
_t._originalScaleX = 1;
|
||||
_t._scaleY = 1;
|
||||
_t._originalScaleY = 1;
|
||||
|
||||
_t._isRotated = false;
|
||||
_t._orientation = 3;
|
||||
_t._isRotated = false;
|
||||
_t._orientation = 3;
|
||||
|
||||
var sys = cc.sys;
|
||||
_t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX);
|
||||
cc.visibleRect && cc.visibleRect.init(_t._visibleRect);
|
||||
var sys = cc.sys;
|
||||
_t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX);
|
||||
cc.visibleRect && cc.visibleRect.init(_t._visibleRect);
|
||||
|
||||
// Setup system default resolution policies
|
||||
_t._resolutionPolicy = null;
|
||||
_t._rpExactFit = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.EXACT_FIT);
|
||||
_t._rpShowAll = new cc.ResolutionPolicy(_strategyer.PROPORTION_TO_FRAME, _strategy.SHOW_ALL);
|
||||
_t._rpNoBorder = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.NO_BORDER);
|
||||
_t._rpFixedHeight = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_HEIGHT);
|
||||
_t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH);
|
||||
// Setup system default resolution policies
|
||||
_t._resolutionPolicy = null;
|
||||
_t._rpExactFit = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.EXACT_FIT);
|
||||
_t._rpShowAll = new cc.ResolutionPolicy(_strategyer.PROPORTION_TO_FRAME, _strategy.SHOW_ALL);
|
||||
_t._rpNoBorder = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.NO_BORDER);
|
||||
_t._rpFixedHeight = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_HEIGHT);
|
||||
_t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH);
|
||||
|
||||
_t._initialized = false;
|
||||
_t._initialized = false;
|
||||
|
||||
_t._contentTranslateLeftTop = null;
|
||||
_t._contentTranslateLeftTop = null;
|
||||
|
||||
_t._frameZoomFactor = 1.0;
|
||||
_t.__resizeWithBrowserSize = false;
|
||||
_t._isAdjustViewPort = true;
|
||||
_t._frameZoomFactor = 1.0;
|
||||
_t.__resizeWithBrowserSize = false;
|
||||
_t._isAdjustViewPort = true;
|
||||
|
||||
_t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH;
|
||||
_t.enableAntiAlias(true);
|
||||
},
|
||||
_t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH;
|
||||
_t.enableAntiAlias(true);
|
||||
};
|
||||
|
||||
View.prototype = {
|
||||
constructor: View,
|
||||
// Resize helper functions
|
||||
_resizeEvent: function () {
|
||||
var view;
|
||||
@@ -986,7 +986,7 @@ var View = cc._Class.extend({
|
||||
selPrePoint.y = (selPrePoint.y - viewport.y) / scaleY;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @method _getInstance
|
||||
@@ -1007,7 +1007,8 @@ View._getInstance = function () {
|
||||
*
|
||||
* @class ContainerStrategy
|
||||
*/
|
||||
cc.ContainerStrategy = cc._Class.extend(/** @lends cc.ContainerStrategy# */{
|
||||
cc.ContainerStrategy = cc.Class({
|
||||
name: "ContainerStrategy",
|
||||
/**
|
||||
* Manipulation before appling the strategy
|
||||
* @method preApply
|
||||
@@ -1079,11 +1080,14 @@ cc.ContainerStrategy = cc._Class.extend(/** @lends cc.ContainerStrategy# */{
|
||||
*
|
||||
* @class ContentStrategy
|
||||
*/
|
||||
cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
cc.ContentStrategy = cc.Class({
|
||||
name: "ContentStrategy",
|
||||
|
||||
_result: {
|
||||
scale: [1, 1],
|
||||
viewport: null
|
||||
ctor: function () {
|
||||
this._result = {
|
||||
scale: [1, 1],
|
||||
viewport: null
|
||||
};
|
||||
},
|
||||
|
||||
_buildResult: function (containerW, containerH, contentW, contentH, scaleX, scaleY) {
|
||||
@@ -1143,7 +1147,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
* @class EqualToFrame
|
||||
* @extends ContainerStrategy
|
||||
*/
|
||||
var EqualToFrame = cc.ContainerStrategy.extend({
|
||||
var EqualToFrame = cc.Class({
|
||||
name: "EqualToFrame",
|
||||
extends: cc.ContainerStrategy,
|
||||
apply: function (view) {
|
||||
var frameH = view._frameSize.height, containerStyle = cc.container.style;
|
||||
this._setupContainer(view, view._frameSize.width, view._frameSize.height);
|
||||
@@ -1162,7 +1168,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
* @class ProportionalToFrame
|
||||
* @extends ContainerStrategy
|
||||
*/
|
||||
var ProportionalToFrame = cc.ContainerStrategy.extend({
|
||||
var ProportionalToFrame = cc.Class({
|
||||
name: "ProportionalToFrame",
|
||||
extends: cc.ContainerStrategy,
|
||||
apply: function (view, designedResolution) {
|
||||
var frameW = view._frameSize.width, frameH = view._frameSize.height, containerStyle = cc.container.style,
|
||||
designW = designedResolution.width, designH = designedResolution.height,
|
||||
@@ -1198,7 +1206,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
* @class EqualToWindow
|
||||
* @extends EqualToFrame
|
||||
*/
|
||||
var EqualToWindow = EqualToFrame.extend({
|
||||
var EqualToWindow = cc.Class({
|
||||
name: "EqualToWindow",
|
||||
extends: EqualToFrame,
|
||||
preApply: function (view) {
|
||||
this._super(view);
|
||||
cc.game.frame = document.documentElement;
|
||||
@@ -1214,7 +1224,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
* @class ProportionalToWindow
|
||||
* @extends ProportionalToFrame
|
||||
*/
|
||||
var ProportionalToWindow = ProportionalToFrame.extend({
|
||||
var ProportionalToWindow = cc.Class({
|
||||
name: "ProportionalToWindow",
|
||||
extends: ProportionalToFrame,
|
||||
preApply: function (view) {
|
||||
this._super(view);
|
||||
cc.game.frame = document.documentElement;
|
||||
@@ -1230,7 +1242,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
* @class OriginalContainer
|
||||
* @extends ContainerStrategy
|
||||
*/
|
||||
var OriginalContainer = cc.ContainerStrategy.extend({
|
||||
var OriginalContainer = cc.Class({
|
||||
name: "OriginalContainer",
|
||||
extends: cc.ContainerStrategy,
|
||||
apply: function (view) {
|
||||
this._setupContainer(view, cc.game.canvas.width, cc.game.canvas.height);
|
||||
}
|
||||
@@ -1248,7 +1262,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
cc.ContainerStrategy.ORIGINAL_CONTAINER = new OriginalContainer();
|
||||
|
||||
// Content scale strategys
|
||||
var ExactFit = cc.ContentStrategy.extend({
|
||||
var ExactFit = cc.Class({
|
||||
name: "ExactFit",
|
||||
extends: cc.ContentStrategy,
|
||||
apply: function (view, designedResolution) {
|
||||
var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height,
|
||||
scaleX = containerW / designedResolution.width, scaleY = containerH / designedResolution.height;
|
||||
@@ -1257,7 +1273,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
}
|
||||
});
|
||||
|
||||
var ShowAll = cc.ContentStrategy.extend({
|
||||
var ShowAll = cc.Class({
|
||||
name: "ShowAll",
|
||||
extends: cc.ContentStrategy,
|
||||
apply: function (view, designedResolution) {
|
||||
var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height,
|
||||
designW = designedResolution.width, designH = designedResolution.height,
|
||||
@@ -1271,7 +1289,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
}
|
||||
});
|
||||
|
||||
var NoBorder = cc.ContentStrategy.extend({
|
||||
var NoBorder = cc.Class({
|
||||
name: "NoBorder",
|
||||
extends: cc.ContentStrategy,
|
||||
apply: function (view, designedResolution) {
|
||||
var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height,
|
||||
designW = designedResolution.width, designH = designedResolution.height,
|
||||
@@ -1285,7 +1305,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
}
|
||||
});
|
||||
|
||||
var FixedHeight = cc.ContentStrategy.extend({
|
||||
var FixedHeight = cc.Class({
|
||||
name: "FixedHeight",
|
||||
extends: cc.ContentStrategy,
|
||||
apply: function (view, designedResolution) {
|
||||
var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height,
|
||||
designH = designedResolution.height, scale = containerH / designH,
|
||||
@@ -1299,7 +1321,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
}
|
||||
});
|
||||
|
||||
var FixedWidth = cc.ContentStrategy.extend({
|
||||
var FixedWidth = cc.Class({
|
||||
name: "FixedWidth",
|
||||
extends: cc.ContentStrategy,
|
||||
apply: function (view, designedResolution) {
|
||||
var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height,
|
||||
designW = designedResolution.width, scale = containerW / designW,
|
||||
@@ -1337,16 +1361,16 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{
|
||||
* @param {ContainerStrategy} containerStg The container strategy
|
||||
* @param {ContentStrategy} contentStg The content strategy
|
||||
*/
|
||||
cc.ResolutionPolicy = cc._Class.extend(/** @lends cc.ResolutionPolicy# */{
|
||||
_containerStrategy: null,
|
||||
_contentStrategy: null,
|
||||
|
||||
cc.ResolutionPolicy = cc.Class({
|
||||
name: "cc.ResolutionPolicy",
|
||||
/**
|
||||
* Constructor of cc.ResolutionPolicy
|
||||
* @param {ContainerStrategy} containerStg
|
||||
* @param {ContentStrategy} contentStg
|
||||
*/
|
||||
ctor: function (containerStg, contentStg) {
|
||||
this._containerStrategy = null;
|
||||
this._contentStrategy = null;
|
||||
this.setContainerStrategy(containerStg);
|
||||
this.setContentStrategy(contentStg);
|
||||
},
|
||||
@@ -1406,7 +1430,7 @@ cc.ResolutionPolicy = cc._Class.extend(/** @lends cc.ResolutionPolicy# */{
|
||||
}
|
||||
});
|
||||
|
||||
cc.js.get(cc.ResolutionPolicy.prototype, "canvasSize", function () {
|
||||
js.get(cc.ResolutionPolicy.prototype, "canvasSize", function () {
|
||||
return cc.v2(cc.game.canvas.width, cc.game.canvas.height);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,227 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* ClassManager
|
||||
*/
|
||||
var ClassManager = cc.ClassManager = {
|
||||
instanceId: (0 | (Math.random() * 998)),
|
||||
getNewInstanceId: function () {
|
||||
return this.instanceId++;
|
||||
}
|
||||
};
|
||||
|
||||
/* Managed JavaScript Inheritance
|
||||
* Based on John Resig's Simple JavaScript Inheritance http://ejohn.org/blog/simple-javascript-inheritance/
|
||||
* MIT Licensed.
|
||||
*/
|
||||
var fnTest = /\b_super\b/;
|
||||
|
||||
/**
|
||||
* The base Class implementation (does nothing)
|
||||
* @class Class
|
||||
* @private
|
||||
*/
|
||||
var Class = function () {
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Class that inherits from this Class
|
||||
* @static
|
||||
* @param {Object} props
|
||||
* @return {Function}
|
||||
*/
|
||||
Class.extend = function (props) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base Class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
var proto = Object.create(_super);
|
||||
|
||||
// Copy the properties over onto the new prototype. We make function
|
||||
// properties non-eumerable as this makes typeof === 'function' check
|
||||
// unnecessary in the for...in loop used 1) for generating Class()
|
||||
// 2) for cc.clone and perhaps more. It is also required to make
|
||||
// these function properties cacheable in Carakan.
|
||||
var desc = { writable: true, enumerable: false, configurable: true };
|
||||
|
||||
// The dummy Class constructor
|
||||
var TheClass;
|
||||
if (CC_SUPPORT_JIT && cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) {
|
||||
var ctor =
|
||||
"return (function " + (props._className || "Class") + "(arg0,arg1,arg2,arg3,arg4) {\n" +
|
||||
"this.__instanceId = cc.ClassManager.getNewInstanceId();\n" +
|
||||
"if (this.ctor) {\n" +
|
||||
"switch (arguments.length) {\n" +
|
||||
"case 0: this.ctor(); break;\n" +
|
||||
"case 1: this.ctor(arg0); break;\n" +
|
||||
"case 2: this.ctor(arg0,arg1); break;\n" +
|
||||
"case 3: this.ctor(arg0,arg1,arg2); break;\n" +
|
||||
"case 4: this.ctor(arg0,arg1,arg2,arg3); break;\n" +
|
||||
"case 5: this.ctor(arg0,arg1,arg2,arg3,arg4); break;\n" +
|
||||
"default: this.ctor.apply(this, arguments);\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"});";
|
||||
TheClass = Function(ctor)();
|
||||
}
|
||||
else {
|
||||
TheClass = function (arg0, arg1, arg2, arg3, arg4) {
|
||||
this.__instanceId = ClassManager.getNewInstanceId();
|
||||
if (this.ctor) {
|
||||
switch (arguments.length) {
|
||||
case 0: this.ctor(); break;
|
||||
case 1: this.ctor(arg0); break;
|
||||
case 2: this.ctor(arg0, arg1); break;
|
||||
case 3: this.ctor(arg0, arg1, arg2); break;
|
||||
case 4: this.ctor(arg0, arg1, arg2, arg3); break;
|
||||
case 5: this.ctor(arg0, arg1, arg2, arg3, arg4); break;
|
||||
default: this.ctor.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
TheClass.prototype = proto;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
desc.value = TheClass;
|
||||
Object.defineProperty(proto, 'constructor', desc);
|
||||
|
||||
for (var name in props) {
|
||||
var isFunc = (typeof props[name] === "function");
|
||||
var override = isFunc && (typeof _super[name] === "function");
|
||||
var hasSuperCall = override && fnTest.test(props[name]);
|
||||
|
||||
if (hasSuperCall) {
|
||||
desc.value = (function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-Class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, props[name]);
|
||||
Object.defineProperty(proto, name, desc);
|
||||
} else if (isFunc) {
|
||||
desc.value = props[name];
|
||||
Object.defineProperty(proto, name, desc);
|
||||
} else {
|
||||
proto[name] = props[name];
|
||||
}
|
||||
}
|
||||
|
||||
// And make this Class extendable
|
||||
TheClass.extend = Class.extend;
|
||||
|
||||
//add implementation method
|
||||
TheClass.implement = function (prop) {
|
||||
for (var name in prop) {
|
||||
proto[name] = prop[name];
|
||||
}
|
||||
};
|
||||
return TheClass;
|
||||
};
|
||||
|
||||
/**
|
||||
* Common getter setter configuration function
|
||||
* @method defineGetterSetter
|
||||
* @param {Object} proto - A class prototype or an object to config<br/>
|
||||
* @param {String} prop - Property name
|
||||
* @param {Function} getter - Getter function for the property
|
||||
* @param {Function} setter - Setter function for the property
|
||||
* @param {String} getterName - Name of getter function for the property
|
||||
* @param {String} setterName - Name of setter function for the property
|
||||
*/
|
||||
cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, setterName) {
|
||||
if (proto.__defineGetter__) {
|
||||
getter && proto.__defineGetter__(prop, getter);
|
||||
setter && proto.__defineSetter__(prop, setter);
|
||||
} else if (Object.defineProperty) {
|
||||
var desc = { configurable: true }; // enumerable is false by default
|
||||
getter && (desc.get = getter);
|
||||
setter && (desc.set = setter);
|
||||
Object.defineProperty(proto, prop, desc);
|
||||
} else {
|
||||
throw new Error(cc._getError(3658));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new object and copy all properties in an exist object to the new object
|
||||
* @method clone
|
||||
* @param {Object|Array} obj - The source object
|
||||
* @return {Array|Object} The created object
|
||||
*/
|
||||
cc.clone = function (obj) {
|
||||
// Cloning is better if the new object is having the same prototype chain
|
||||
// as the copied obj (or otherwise, the cloned object is certainly going to
|
||||
// have a different hidden class). Play with C1/C2 of the
|
||||
// PerformanceVirtualMachineTests suite to see how this makes an impact
|
||||
// under extreme conditions.
|
||||
//
|
||||
// Object.create(Object.getPrototypeOf(obj)) doesn't work well because the
|
||||
// prototype lacks a link to the constructor (Carakan, V8) so the new
|
||||
// object wouldn't have the hidden class that's associated with the
|
||||
// constructor (also, for whatever reasons, utilizing
|
||||
// Object.create(Object.getPrototypeOf(obj)) + Object.defineProperty is even
|
||||
// slower than the original in V8). Therefore, we call the constructor, but
|
||||
// there is a big caveat - it is possible that the this.init() in the
|
||||
// constructor would throw with no argument. It is also possible that a
|
||||
// derived class forgets to set "constructor" on the prototype. We ignore
|
||||
// these possibities for and the ultimate solution is a standardized
|
||||
// Object.clone(<object>).
|
||||
var newObj = (obj.constructor) ? new obj.constructor : {};
|
||||
|
||||
// Assuming that the constuctor above initialized all properies on obj, the
|
||||
// following keyed assignments won't turn newObj into dictionary mode
|
||||
// becasue they're not *appending new properties* but *assigning existing
|
||||
// ones* (note that appending indexed properties is another story). See
|
||||
// CCClass.js for a link to the devils when the assumption fails.
|
||||
for (var key in obj) {
|
||||
var copy = obj[key];
|
||||
// Beware that typeof null == "object" !
|
||||
if (typeof copy === "object" &&
|
||||
copy &&
|
||||
!(copy instanceof _ccsg.Node) &&
|
||||
(CC_JSB || !(copy instanceof HTMLElement))) {
|
||||
newObj[key] = cc.clone(copy);
|
||||
} else {
|
||||
newObj[key] = copy;
|
||||
}
|
||||
}
|
||||
return newObj;
|
||||
};
|
||||
|
||||
cc._Class = module.exports = Class;
|
||||
@@ -29,6 +29,8 @@ const RenderData = renderEngine.RenderData;
|
||||
const Label = require('../../../components/CCLabel');
|
||||
const Overflow = Label.Overflow;
|
||||
|
||||
const TextUtils = require('../../../utils/text-utils').TextUtils;
|
||||
|
||||
const spriteAssembler = require('../sprite/simple');
|
||||
|
||||
let FontLetterDefinition = function() {
|
||||
@@ -315,7 +317,7 @@ module.exports = {
|
||||
&& _maxLineWidth > 0
|
||||
&& nextTokenX > 0
|
||||
&& letterX + letterDef._width * _bmfontScale > _maxLineWidth
|
||||
&& !cc.TextUtils.isUnicodeSpace(character)) {
|
||||
&& !TextUtils.isUnicodeSpace(character)) {
|
||||
_linesWidth.push(letterRight);
|
||||
letterRight = 0;
|
||||
lineIndex++;
|
||||
@@ -401,9 +403,9 @@ module.exports = {
|
||||
|
||||
_getFirstWordLen: function(text, startIndex, textLen) {
|
||||
let character = text.charAt(startIndex);
|
||||
if (cc.TextUtils.isUnicodeCJK(character)
|
||||
if (TextUtils.isUnicodeCJK(character)
|
||||
|| character === "\n"
|
||||
|| cc.TextUtils.isUnicodeSpace(character)) {
|
||||
|| TextUtils.isUnicodeSpace(character)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -424,14 +426,14 @@ module.exports = {
|
||||
letterX = nextLetterX + letterDef._offsetX * _bmfontScale;
|
||||
|
||||
if(letterX + letterDef._width * _bmfontScale > _maxLineWidth
|
||||
&& !cc.TextUtils.isUnicodeSpace(character)
|
||||
&& !TextUtils.isUnicodeSpace(character)
|
||||
&& _maxLineWidth > 0) {
|
||||
return len;
|
||||
}
|
||||
nextLetterX += letterDef._xAdvance * _bmfontScale + _spacingX;
|
||||
if (character === "\n"
|
||||
|| cc.TextUtils.isUnicodeSpace(character)
|
||||
|| cc.TextUtils.isUnicodeCJK(character)) {
|
||||
|| TextUtils.isUnicodeSpace(character)
|
||||
|| TextUtils.isUnicodeCJK(character)) {
|
||||
break;
|
||||
}
|
||||
len++;
|
||||
|
||||
@@ -29,6 +29,9 @@ const RenderData = renderEngine.RenderData;
|
||||
const Label = require('../../../components/CCLabel');
|
||||
const LabelOutline = require('../../../components/CCLabelOutline');
|
||||
const Overflow = Label.Overflow;
|
||||
const utils = require('../../../utils/text-utils');
|
||||
const TextUtils = utils.TextUtils;
|
||||
const CustomFontLoader = utils.CustomFontLoader;
|
||||
|
||||
const spriteAssembler = require('../sprite/simple');
|
||||
|
||||
@@ -179,10 +182,10 @@ module.exports = {
|
||||
if (!_comp.font) return false;
|
||||
|
||||
let url = _comp.font.nativeUrl;
|
||||
_fontFamily = cc.CustomFontLoader._getFontFamily(url);
|
||||
let fontDescriptor = cc.CustomFontLoader._fontCache[_fontFamily];
|
||||
_fontFamily = CustomFontLoader._getFontFamily(url);
|
||||
let fontDescriptor = CustomFontLoader._fontCache[_fontFamily];
|
||||
if (!fontDescriptor || !fontDescriptor.isLoaded()) {
|
||||
cc.CustomFontLoader.loadTTF(url);
|
||||
CustomFontLoader.loadTTF(url);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -398,10 +401,10 @@ module.exports = {
|
||||
var canvasWidthNoMargin = _canvasSize.width - 2 * _margin;
|
||||
for (i = 0; i < paragraphedStrings.length; ++i) {
|
||||
var allWidth = _context.measureText(paragraphedStrings[i]).width;
|
||||
var textFragment = cc.TextUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context));
|
||||
var textFragment = TextUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context));
|
||||
_splitedStrings = _splitedStrings.concat(textFragment);
|
||||
}
|
||||
}
|
||||
@@ -498,10 +501,10 @@ module.exports = {
|
||||
for (i = 0; i < paragraphedStrings.length; ++i) {
|
||||
var j = 0;
|
||||
var allWidth = _context.measureText(paragraphedStrings[i]).width;
|
||||
textFragment = cc.TextUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context));
|
||||
textFragment = TextUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context));
|
||||
while (j < textFragment.length) {
|
||||
var measureWidth = _context.measureText(textFragment[j]).width;
|
||||
maxLength = measureWidth;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
var PStats = require('../../../external/pstats/pstats');
|
||||
var macro = require('../platform/CCMacro');
|
||||
var renderer = require('../renderer');
|
||||
|
||||
var _fps = document.createElement('div');
|
||||
_fps.id = 'fps';
|
||||
@@ -51,7 +50,7 @@ function afterVisit () {
|
||||
|
||||
function afterDraw () {
|
||||
stats('render').end();
|
||||
stats('draws').value = renderer.drawCalls;
|
||||
stats('draws').value = cc.renderer.drawCalls;
|
||||
stats('frame').end();
|
||||
stats('fps').frame();
|
||||
stats().tick();
|
||||
|
||||
@@ -27,7 +27,7 @@ var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*click
|
||||
/**
|
||||
* A utils class for parsing HTML texts. The parsed results will be an object array.
|
||||
*/
|
||||
cc.HtmlTextParser = function() {
|
||||
var HtmlTextParser = function() {
|
||||
this._parsedObject = {};
|
||||
this._specialSymbolArray = [];
|
||||
this._specialSymbolArray.push([/</g, '<']);
|
||||
@@ -37,8 +37,8 @@ cc.HtmlTextParser = function() {
|
||||
this._specialSymbolArray.push([/'/g, '\'']);
|
||||
};
|
||||
|
||||
cc.HtmlTextParser.prototype = {
|
||||
constructor: cc.HtmlTextParser,
|
||||
HtmlTextParser.prototype = {
|
||||
constructor: HtmlTextParser,
|
||||
parse: function(htmlString) {
|
||||
this._resultObjectArray = [];
|
||||
this._stack = [];
|
||||
@@ -325,5 +325,8 @@ cc.HtmlTextParser.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
if (CC_TEST) {
|
||||
cc._Test.HtmlTextParser = HtmlTextParser;
|
||||
}
|
||||
|
||||
cc.htmlTextParser = new cc.HtmlTextParser();
|
||||
module.exports = HtmlTextParser;
|
||||
@@ -23,6 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var HtmlTextParser = require('./html-text-parser');
|
||||
|
||||
var CustomFontDescriptor = function() {
|
||||
this._status = 'unloaded';
|
||||
//when font is loaded, it will notify each observer in the observers array
|
||||
@@ -323,8 +325,10 @@ var TextUtils = {
|
||||
}
|
||||
return wrappedWords;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
cc.TextUtils = module.exports = TextUtils;
|
||||
cc.CustomFontLoader = module.exports = CustomFontLoader;
|
||||
module.exports = {
|
||||
HtmlTextParser: HtmlTextParser,
|
||||
TextUtils: TextUtils,
|
||||
CustomFontLoader: CustomFontLoader
|
||||
}
|
||||
@@ -603,13 +603,18 @@ if (CC_DEV) {
|
||||
// cc
|
||||
markAsRemovedInObject(cc, ['Scale9Sprite'], 'cc');
|
||||
|
||||
js.get(cc, 'pool', function () {
|
||||
cc.warnID(1407);
|
||||
return js.Pool;
|
||||
});
|
||||
|
||||
if (cc.ActionManager) {
|
||||
js.obsoletes(cc.ActionManager.prototype, 'cc.ActionManager', {
|
||||
'numberOfRunningActionsInTarget' : 'getNumberOfRunningActionsInTarget'
|
||||
});
|
||||
}
|
||||
|
||||
cc.js.get(cc.Texture2D.prototype, 'getName', function () {
|
||||
js.get(cc.Texture2D.prototype, 'getName', function () {
|
||||
cc.warnID(1400, 'texture.getName()', 'texture._glID');
|
||||
return function () {
|
||||
return this._glID || null;
|
||||
|
||||
+1
-3
@@ -1,6 +1,4 @@
|
||||
require('./core/CCGame');
|
||||
|
||||
// ensure modular-cocos2d can determine whether action module is included
|
||||
require('./actions');
|
||||
|
||||
require('./core/CCConfiguration');
|
||||
require('./actions');
|
||||
+127
-126
@@ -32,139 +32,140 @@ var Zlib = require('../compression/zlib.min');
|
||||
* A png file reader
|
||||
* @name PNGReader
|
||||
*/
|
||||
var PNGReader = cc._Class.extend({
|
||||
ctor:function(data){
|
||||
var chunkSize, colors, delayDen, delayNum, frame, i, index, key, section, ccshort, text, _i, _j, _ref;
|
||||
this.data = data;
|
||||
this.pos = 8;
|
||||
this.palette = [];
|
||||
this.imgData = [];
|
||||
this.transparency = {};
|
||||
this.animation = null;
|
||||
this.text = {};
|
||||
frame = null;
|
||||
while (true) {
|
||||
chunkSize = this.readUInt32();
|
||||
section = ((function() {
|
||||
var _i, _results;
|
||||
_results = [];
|
||||
for (i = _i = 0; _i < 4; i = ++_i) {
|
||||
_results.push(String.fromCharCode(this.data[this.pos++]));
|
||||
var PNGReader = function(data){
|
||||
var chunkSize, colors, delayDen, delayNum, frame, i, index, key, section, ccshort, text, _i, _j, _ref;
|
||||
this.data = data;
|
||||
this.pos = 8;
|
||||
this.palette = [];
|
||||
this.imgData = [];
|
||||
this.transparency = {};
|
||||
this.animation = null;
|
||||
this.text = {};
|
||||
frame = null;
|
||||
while (true) {
|
||||
chunkSize = this.readUInt32();
|
||||
section = ((function() {
|
||||
var _i, _results;
|
||||
_results = [];
|
||||
for (i = _i = 0; _i < 4; i = ++_i) {
|
||||
_results.push(String.fromCharCode(this.data[this.pos++]));
|
||||
}
|
||||
return _results;
|
||||
}).call(this)).join('');
|
||||
switch (section) {
|
||||
case 'IHDR':
|
||||
this.width = this.readUInt32();
|
||||
this.height = this.readUInt32();
|
||||
this.bits = this.data[this.pos++];
|
||||
this.colorType = this.data[this.pos++];
|
||||
this.compressionMethod = this.data[this.pos++];
|
||||
this.filterMethod = this.data[this.pos++];
|
||||
this.interlaceMethod = this.data[this.pos++];
|
||||
break;
|
||||
case 'acTL':
|
||||
this.animation = {
|
||||
numFrames: this.readUInt32(),
|
||||
numPlays: this.readUInt32() || Infinity,
|
||||
frames: []
|
||||
};
|
||||
break;
|
||||
case 'PLTE':
|
||||
this.palette = this.read(chunkSize);
|
||||
break;
|
||||
case 'fcTL':
|
||||
if (frame) {
|
||||
this.animation.frames.push(frame);
|
||||
}
|
||||
return _results;
|
||||
}).call(this)).join('');
|
||||
switch (section) {
|
||||
case 'IHDR':
|
||||
this.width = this.readUInt32();
|
||||
this.height = this.readUInt32();
|
||||
this.bits = this.data[this.pos++];
|
||||
this.colorType = this.data[this.pos++];
|
||||
this.compressionMethod = this.data[this.pos++];
|
||||
this.filterMethod = this.data[this.pos++];
|
||||
this.interlaceMethod = this.data[this.pos++];
|
||||
break;
|
||||
case 'acTL':
|
||||
this.animation = {
|
||||
numFrames: this.readUInt32(),
|
||||
numPlays: this.readUInt32() || Infinity,
|
||||
frames: []
|
||||
};
|
||||
break;
|
||||
case 'PLTE':
|
||||
this.palette = this.read(chunkSize);
|
||||
break;
|
||||
case 'fcTL':
|
||||
if (frame) {
|
||||
this.animation.frames.push(frame);
|
||||
}
|
||||
this.pos += 4;
|
||||
frame = {
|
||||
width: this.readUInt32(),
|
||||
height: this.readUInt32(),
|
||||
xOffset: this.readUInt32(),
|
||||
yOffset: this.readUInt32()
|
||||
};
|
||||
delayNum = this.readUInt16();
|
||||
delayDen = this.readUInt16() || 100;
|
||||
frame.delay = 1000 * delayNum / delayDen;
|
||||
frame.disposeOp = this.data[this.pos++];
|
||||
frame.blendOp = this.data[this.pos++];
|
||||
frame.data = [];
|
||||
break;
|
||||
case 'IDAT':
|
||||
case 'fdAT':
|
||||
if (section === 'fdAT') {
|
||||
this.pos += 4;
|
||||
frame = {
|
||||
width: this.readUInt32(),
|
||||
height: this.readUInt32(),
|
||||
xOffset: this.readUInt32(),
|
||||
yOffset: this.readUInt32()
|
||||
};
|
||||
delayNum = this.readUInt16();
|
||||
delayDen = this.readUInt16() || 100;
|
||||
frame.delay = 1000 * delayNum / delayDen;
|
||||
frame.disposeOp = this.data[this.pos++];
|
||||
frame.blendOp = this.data[this.pos++];
|
||||
frame.data = [];
|
||||
break;
|
||||
case 'IDAT':
|
||||
case 'fdAT':
|
||||
if (section === 'fdAT') {
|
||||
this.pos += 4;
|
||||
chunkSize -= 4;
|
||||
}
|
||||
data = (frame != null ? frame.data : void 0) || this.imgData;
|
||||
for (i = _i = 0; 0 <= chunkSize ? _i < chunkSize : _i > chunkSize; i = 0 <= chunkSize ? ++_i : --_i) {
|
||||
data.push(this.data[this.pos++]);
|
||||
}
|
||||
break;
|
||||
case 'tRNS':
|
||||
this.transparency = {};
|
||||
switch (this.colorType) {
|
||||
case 3:
|
||||
this.transparency.indexed = this.read(chunkSize);
|
||||
ccshort = 255 - this.transparency.indexed.length;
|
||||
if (ccshort > 0) {
|
||||
for (i = _j = 0; 0 <= ccshort ? _j < ccshort : _j > ccshort; i = 0 <= ccshort ? ++_j : --_j) {
|
||||
this.transparency.indexed.push(255);
|
||||
}
|
||||
chunkSize -= 4;
|
||||
}
|
||||
data = (frame != null ? frame.data : void 0) || this.imgData;
|
||||
for (i = _i = 0; 0 <= chunkSize ? _i < chunkSize : _i > chunkSize; i = 0 <= chunkSize ? ++_i : --_i) {
|
||||
data.push(this.data[this.pos++]);
|
||||
}
|
||||
break;
|
||||
case 'tRNS':
|
||||
this.transparency = {};
|
||||
switch (this.colorType) {
|
||||
case 3:
|
||||
this.transparency.indexed = this.read(chunkSize);
|
||||
ccshort = 255 - this.transparency.indexed.length;
|
||||
if (ccshort > 0) {
|
||||
for (i = _j = 0; 0 <= ccshort ? _j < ccshort : _j > ccshort; i = 0 <= ccshort ? ++_j : --_j) {
|
||||
this.transparency.indexed.push(255);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
this.transparency.grayscale = this.read(chunkSize)[0];
|
||||
break;
|
||||
case 2:
|
||||
this.transparency.rgb = this.read(chunkSize);
|
||||
}
|
||||
break;
|
||||
case 'tEXt':
|
||||
text = this.read(chunkSize);
|
||||
index = text.indexOf(0);
|
||||
key = String.fromCharCode.apply(String, text.slice(0, index));
|
||||
this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1));
|
||||
break;
|
||||
case 'IEND':
|
||||
if (frame) {
|
||||
this.animation.frames.push(frame);
|
||||
}
|
||||
this.colors = (function() {
|
||||
switch (this.colorType) {
|
||||
case 0:
|
||||
this.transparency.grayscale = this.read(chunkSize)[0];
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
return 1;
|
||||
case 2:
|
||||
this.transparency.rgb = this.read(chunkSize);
|
||||
case 6:
|
||||
return 3;
|
||||
}
|
||||
break;
|
||||
case 'tEXt':
|
||||
text = this.read(chunkSize);
|
||||
index = text.indexOf(0);
|
||||
key = String.fromCharCode.apply(String, text.slice(0, index));
|
||||
this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1));
|
||||
break;
|
||||
case 'IEND':
|
||||
if (frame) {
|
||||
this.animation.frames.push(frame);
|
||||
}).call(this);
|
||||
this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6;
|
||||
colors = this.colors + (this.hasAlphaChannel ? 1 : 0);
|
||||
this.pixelBitlength = this.bits * colors;
|
||||
this.colorSpace = (function() {
|
||||
switch (this.colors) {
|
||||
case 1:
|
||||
return 'DeviceGray';
|
||||
case 3:
|
||||
return 'DeviceRGB';
|
||||
}
|
||||
this.colors = (function() {
|
||||
switch (this.colorType) {
|
||||
case 0:
|
||||
case 3:
|
||||
case 4:
|
||||
return 1;
|
||||
case 2:
|
||||
case 6:
|
||||
return 3;
|
||||
}
|
||||
}).call(this);
|
||||
this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6;
|
||||
colors = this.colors + (this.hasAlphaChannel ? 1 : 0);
|
||||
this.pixelBitlength = this.bits * colors;
|
||||
this.colorSpace = (function() {
|
||||
switch (this.colors) {
|
||||
case 1:
|
||||
return 'DeviceGray';
|
||||
case 3:
|
||||
return 'DeviceRGB';
|
||||
}
|
||||
}).call(this);
|
||||
if(Uint8Array != Array)
|
||||
this.imgData = new Uint8Array(this.imgData);
|
||||
return;
|
||||
default:
|
||||
this.pos += chunkSize;
|
||||
}
|
||||
this.pos += 4;
|
||||
if (this.pos > this.data.length) {
|
||||
throw new Error(cc._getError(6017));
|
||||
}
|
||||
}).call(this);
|
||||
if(Uint8Array != Array)
|
||||
this.imgData = new Uint8Array(this.imgData);
|
||||
return;
|
||||
default:
|
||||
this.pos += chunkSize;
|
||||
}
|
||||
},
|
||||
this.pos += 4;
|
||||
if (this.pos > this.data.length) {
|
||||
throw new Error(cc._getError(6017));
|
||||
}
|
||||
}
|
||||
};
|
||||
PNGReader.prototype = {
|
||||
constructor: PNGReader,
|
||||
read:function(bytes){
|
||||
var i, _i, _results;
|
||||
_results = [];
|
||||
@@ -328,6 +329,6 @@ var PNGReader = cc._Class.extend({
|
||||
return ctx.putImageData(data, 0, 0);
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = PNGReader;
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
var codec = require('../compression/ZipUtils');
|
||||
var Zlib = require('../compression/zlib.min');
|
||||
var js = require('../core/platform/js');
|
||||
|
||||
function uint8ArrayToUint32Array (uint8Arr) {
|
||||
if(uint8Arr.length % 4 !== 0)
|
||||
@@ -50,26 +51,25 @@ function uint8ArrayToUint32Array (uint8Arr) {
|
||||
* - Whether the layer is visible (if it's not visible, then the CocosNode won't be created) <br />
|
||||
* <br />
|
||||
* This information is obtained from the TMX file.</p>
|
||||
* @class
|
||||
* @extends cc._Class
|
||||
* @class TMXLayerInfo
|
||||
*
|
||||
* @property {Array} properties - Properties of the layer info.
|
||||
*/
|
||||
cc.TMXLayerInfo = cc._Class.extend(/** @lends cc.TMXLayerInfo# */{
|
||||
|
||||
ctor () {
|
||||
this.properties = {};
|
||||
this.name = "";
|
||||
this._layerSize = null;
|
||||
this._tiles = [];
|
||||
this.visible = true;
|
||||
this._opacity = 0;
|
||||
this.ownTiles = true;
|
||||
this._minGID = 100000;
|
||||
this._maxGID = 0;
|
||||
this.offset = cc.p(0,0);
|
||||
},
|
||||
cc.TMXLayerInfo = function () {
|
||||
this.properties = {};
|
||||
this.name = "";
|
||||
this._layerSize = null;
|
||||
this._tiles = [];
|
||||
this.visible = true;
|
||||
this._opacity = 0;
|
||||
this.ownTiles = true;
|
||||
this._minGID = 100000;
|
||||
this._maxGID = 0;
|
||||
this.offset = cc.p(0,0);
|
||||
};
|
||||
|
||||
cc.TMXLayerInfo.prototype = {
|
||||
constructor: cc.TMXLayerInfo,
|
||||
/**
|
||||
* Gets the Properties.
|
||||
* @return {Array}
|
||||
@@ -85,7 +85,7 @@ cc.TMXLayerInfo = cc._Class.extend(/** @lends cc.TMXLayerInfo# */{
|
||||
setProperties (value) {
|
||||
this.properties = value;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>cc.TMXObjectGroupInfo contains the information about the object group like: <br />
|
||||
@@ -95,24 +95,23 @@ cc.TMXLayerInfo = cc._Class.extend(/** @lends cc.TMXLayerInfo# */{
|
||||
* - Whether the group is visible <br />
|
||||
* <br />
|
||||
* This information is obtained from the TMX file.</p>
|
||||
* @class
|
||||
* @extends cc._Class
|
||||
* @class TMXObjectGroupInfo
|
||||
*
|
||||
* @property {Array} properties - Properties of the ObjectGroup info.
|
||||
*/
|
||||
cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{
|
||||
|
||||
ctor () {
|
||||
this.properties = {};
|
||||
this.name = "";
|
||||
this._objects = [];
|
||||
this.visible = true;
|
||||
this._opacity = 0;
|
||||
this._color = new cc.Color(255, 255, 255, 255);
|
||||
this.offset = cc.p(0,0);
|
||||
this._draworder = 'topdown';
|
||||
},
|
||||
cc.TMXObjectGroupInfo = function () {
|
||||
this.properties = {};
|
||||
this.name = "";
|
||||
this._objects = [];
|
||||
this.visible = true;
|
||||
this._opacity = 0;
|
||||
this._color = new cc.Color(255, 255, 255, 255);
|
||||
this.offset = cc.p(0,0);
|
||||
this._draworder = 'topdown';
|
||||
};
|
||||
|
||||
cc.TMXObjectGroupInfo.prototype = {
|
||||
constructor: cc.TMXObjectGroupInfo,
|
||||
/**
|
||||
* Gets the Properties.
|
||||
* @return {Array}
|
||||
@@ -128,7 +127,7 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{
|
||||
setProperties (value) {
|
||||
this.properties = value;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>cc.TMXTilesetInfo contains the information about the tilesets like: <br />
|
||||
@@ -140,8 +139,7 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{
|
||||
* - Image size<br />
|
||||
*
|
||||
* This information is obtained from the TMX file. </p>
|
||||
* @class
|
||||
* @extends cc._Class
|
||||
* @class TMXTilesetInfo
|
||||
*
|
||||
* @property {string} name - Tileset name
|
||||
* @property {number} firstGid - First grid
|
||||
@@ -150,27 +148,26 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{
|
||||
* @property {null} sourceImage - Texture containing the tiles (should be sprite sheet / texture atlas)
|
||||
* @property {cc.Size} imageSize - Size in pixels of the image
|
||||
*/
|
||||
cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{
|
||||
cc.TMXTilesetInfo = function () {
|
||||
// Tileset name
|
||||
this.name = "";
|
||||
// First grid
|
||||
this.firstGid = 0;
|
||||
// Spacing
|
||||
this.spacing = 0;
|
||||
// Margin
|
||||
this.margin = 0;
|
||||
// Texture containing the tiles (should be sprite sheet / texture atlas)
|
||||
this.sourceImage = null;
|
||||
// Size in pixels of the image
|
||||
this.imageSize = cc.size(0, 0);
|
||||
|
||||
ctor () {
|
||||
// Tileset name
|
||||
this.name = "";
|
||||
// First grid
|
||||
this.firstGid = 0;
|
||||
// Spacing
|
||||
this.spacing = 0;
|
||||
// Margin
|
||||
this.margin = 0;
|
||||
// Texture containing the tiles (should be sprite sheet / texture atlas)
|
||||
this.sourceImage = null;
|
||||
// Size in pixels of the image
|
||||
this.imageSize = cc.size(0, 0);
|
||||
|
||||
this.tileOffset = cc.p(0, 0);
|
||||
|
||||
this._tileSize = cc.size(0, 0);
|
||||
},
|
||||
this.tileOffset = cc.p(0, 0);
|
||||
|
||||
this._tileSize = cc.size(0, 0);
|
||||
};
|
||||
cc.TMXTilesetInfo.prototype = {
|
||||
constructor: cc.TMXTilesetInfo,
|
||||
/**
|
||||
* Return rect
|
||||
* @param {Number} gid
|
||||
@@ -187,7 +184,7 @@ cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{
|
||||
rect.y = parseInt(parseInt(gid / max_x, 10) * (this._tileSize.height + this.spacing) + this.margin, 10);
|
||||
return rect;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function getPropertyList (node) {
|
||||
let res = [];
|
||||
@@ -241,53 +238,46 @@ function getPropertyList (node) {
|
||||
* let xmlStr = cc.loader.getRes(filePath);
|
||||
* let tmxMapInfo = new cc.TMXMapInfo(xmlStr, resources);
|
||||
*/
|
||||
cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
properties:null,
|
||||
orientation:null,
|
||||
parentElement:null,
|
||||
parentGID:null,
|
||||
layerAttrs:0,
|
||||
storingCharacters:false,
|
||||
currentString:null,
|
||||
|
||||
_objectGroups:null,
|
||||
_allChildren: null,
|
||||
_mapSize:null,
|
||||
_tileSize:null,
|
||||
_layers:null,
|
||||
_tilesets:null,
|
||||
// tile properties
|
||||
_tileProperties:null,
|
||||
_resources: "", // used to load relative tsx
|
||||
/**
|
||||
* Creates a TMX Format with a tmx file or content string <br/>
|
||||
* Constructor of cc.TMXMapInfo
|
||||
* @method constructor
|
||||
* @param {String} tmxFile content string
|
||||
* @param {String} resourcePath
|
||||
* @param {Object} textures
|
||||
*/
|
||||
cc.TMXMapInfo = function (tmxFile, resourcePath, textures) {
|
||||
this.properties = [];
|
||||
this.orientation = null;
|
||||
this.parentElement = null;
|
||||
this.parentGID = null;
|
||||
this.layerAttrs = 0;
|
||||
this.storingCharacters = false;
|
||||
this.currentString = null;
|
||||
|
||||
this._parser = new cc.SAXParser();
|
||||
this._objectGroups = [];
|
||||
this._allChildren = [];
|
||||
this._mapSize = cc.size(0, 0);
|
||||
this._tileSize = cc.size(0, 0);
|
||||
this._layers = [];
|
||||
this._tilesets = [];
|
||||
this._tileProperties = {};
|
||||
this._resources = "";
|
||||
|
||||
// map of textures indexed by name
|
||||
_textures: null,
|
||||
this._textures = null;
|
||||
|
||||
// hex map values
|
||||
_staggerAxis: null,
|
||||
_staggerIndex: null,
|
||||
_hexSideLength: 0,
|
||||
this._staggerAxis = null;
|
||||
this._staggerIndex = null;
|
||||
this._hexSideLength = 0;
|
||||
|
||||
/**
|
||||
* Creates a TMX Format with a tmx file or content string <br/>
|
||||
* Constructor of cc.TMXMapInfo
|
||||
* @param {String} tmxFile content string
|
||||
* @param {String} resourcePath
|
||||
* @param {Object} textures
|
||||
*/
|
||||
ctor (tmxFile, resourcePath, textures) {
|
||||
cc.SAXParser.prototype.ctor.apply(this);
|
||||
this._mapSize = cc.size(0, 0);
|
||||
this._tileSize = cc.size(0, 0);
|
||||
this._layers = [];
|
||||
this._tilesets = [];
|
||||
this._objectGroups = [];
|
||||
this._allChildren = [];
|
||||
this.properties = [];
|
||||
this._tileProperties = {};
|
||||
|
||||
this.initWithXML(tmxFile, resourcePath, textures);
|
||||
},
|
||||
this.initWithXML(tmxFile, resourcePath, textures);
|
||||
};
|
||||
cc.TMXMapInfo.prototype = {
|
||||
constructor: cc.TMXMapInfo,
|
||||
/**
|
||||
* Gets Map orientation.
|
||||
* @return {Number}
|
||||
@@ -588,7 +578,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
cc.errorID(7220, tmxFile);
|
||||
}
|
||||
|
||||
let mapXML = this._parseXML(xmlStr);
|
||||
let mapXML = this._parser._parseXML(xmlStr);
|
||||
let i, j;
|
||||
|
||||
// PARSE <map>
|
||||
@@ -993,23 +983,15 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
setCurrentString (currentString) {
|
||||
this.currentString = currentString;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let _p = cc.TMXMapInfo.prototype;
|
||||
|
||||
// Extended properties
|
||||
/** @expose */
|
||||
_p.mapWidth;
|
||||
cc.defineGetterSetter(_p, "mapWidth", _p._getMapWidth, _p._setMapWidth);
|
||||
/** @expose */
|
||||
_p.mapHeight;
|
||||
cc.defineGetterSetter(_p, "mapHeight", _p._getMapHeight, _p._setMapHeight);
|
||||
/** @expose */
|
||||
_p.tileWidth;
|
||||
cc.defineGetterSetter(_p, "tileWidth", _p._getTileWidth, _p._setTileWidth);
|
||||
/** @expose */
|
||||
_p.tileHeight;
|
||||
cc.defineGetterSetter(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight);
|
||||
js.getset(_p, "mapWidth", _p._getMapWidth, _p._setMapWidth);
|
||||
js.getset(_p, "mapHeight", _p._getMapHeight, _p._setMapHeight);
|
||||
js.getset(_p, "tileWidth", _p._getTileWidth, _p._setTileWidth);
|
||||
js.getset(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,6 @@ else {
|
||||
require('./cocos2d/motion-streak/CCMotionStreak');
|
||||
require('./cocos2d/core/components/CCStudioComponent');
|
||||
require('./extensions/ccpool/CCNodePool');
|
||||
require('./extensions/ccpool/CCPool');
|
||||
if (!CC_JSB) {
|
||||
require('./cocos2d/actions');
|
||||
require('./external/chipmunk/chipmunk');
|
||||
|
||||
@@ -1,149 +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.
|
||||
****************************************************************************/
|
||||
|
||||
var _args = [];
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Attention: In creator, it's strongly not recommended to use cc.pool to manager cc.Node.
|
||||
* We provided {{#crossLink "NodePool"}}cc.NodePool{{/crossLink}} instead.
|
||||
*
|
||||
* cc.pool is a singleton object serves as an object cache pool.<br/>
|
||||
* It can helps you to improve your game performance for objects which need frequent release and recreate operations<br/>
|
||||
* !#zh
|
||||
* 首先请注意,在 Creator 中我们强烈不建议使用 cc.pool 来管理 cc.Node 节点对象,请使用 {{#crossLink "NodePool"}}cc.NodePool{{/crossLink}} 代替
|
||||
* 因为 cc.pool 是面向类来设计的,而 cc.Node 中使用 Component 来进行组合,它的类永远都一样,实际却千差万别。
|
||||
*
|
||||
* cc.pool 是一个单例对象,用作为对象缓存池。<br/>
|
||||
* 它可以帮助您提高游戏性能,适用于优化对象的反复创建和销毁<br/>
|
||||
* @class pool
|
||||
* @deprecated !#en Please use cc.NodePool instead !#zh 请使用 cc.NodePool 代替
|
||||
*/
|
||||
cc.pool = /** @lends cc.pool# */{
|
||||
_pool: {},
|
||||
|
||||
_releaseCB: function () {
|
||||
this.release();
|
||||
},
|
||||
|
||||
_autoRelease: function (obj) {
|
||||
var running = obj._running === undefined ? false : !obj._running;
|
||||
cc.director.getScheduler().schedule(this._releaseCB, obj, 0, 0, 0, running);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Put the obj in pool.
|
||||
* !#zh 加入对象到对象池中。
|
||||
* @method putInPool
|
||||
* @param {Object} obj - The need put in pool object.
|
||||
* @example {@link utils/api/engine/docs/extensions/ccpool/putInPool.js}
|
||||
*/
|
||||
putInPool: function (obj) {
|
||||
var cid = cc.js._getClassId(obj.constructor);
|
||||
if (!cid) {
|
||||
return;
|
||||
}
|
||||
if (!this._pool[cid]) {
|
||||
this._pool[cid] = [];
|
||||
}
|
||||
// User implementation for disable the object
|
||||
obj.unuse && obj.unuse();
|
||||
this._pool[cid].push(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Check if this kind of obj has already in pool.
|
||||
* !#zh 检查对象池中是否有指定对象的存在。
|
||||
* @method hasObject
|
||||
* @param {Object} objClass - The check object class.
|
||||
* @returns {Boolean} If this kind of obj is already in pool return true,else return false.
|
||||
*/
|
||||
hasObject: function (objClass) {
|
||||
var cid = cc.js._getClassId(objClass);
|
||||
var list = this._pool[cid];
|
||||
if (!list || list.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Remove the obj if you want to delete it.
|
||||
* !#zh 移除在对象池中指定的对象。
|
||||
* @method removeObject
|
||||
*/
|
||||
removeObject: function (obj) {
|
||||
var cid = cc.js._getClassId(obj.constructor);
|
||||
if (cid) {
|
||||
var list = this._pool[cid];
|
||||
if (list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (obj === list[i]) {
|
||||
list.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Get the obj from pool.
|
||||
* !#zh 获取对象池中的指定对象。
|
||||
* @method getFromPool
|
||||
* @returns {*} Call the reuse function an return the obj.
|
||||
*/
|
||||
getFromPool: function (objClass/*,args*/) {
|
||||
if (this.hasObject(objClass)) {
|
||||
var cid = cc.js._getClassId(objClass);
|
||||
var list = this._pool[cid];
|
||||
_args.length = arguments.length - 1;
|
||||
for (var i = 0; i < _args.length; i++) {
|
||||
_args[i] = arguments[i+1];
|
||||
}
|
||||
var obj = list.pop();
|
||||
// User implementation for re-enable the object
|
||||
obj.reuse && obj.reuse.apply(obj, _args);
|
||||
_args.length = 0;
|
||||
return obj;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Remove all objs in pool and reset the pool.
|
||||
* !#zh 移除对象池中的所有对象,并且重置对象池。
|
||||
* @method drainAllPools
|
||||
*/
|
||||
drainAllPools: function () {
|
||||
if (CC_JSB) {
|
||||
for (var i in this._pool) {
|
||||
for (var j = 0; j < this._pool[i].length; j++) {
|
||||
var obj = this._pool[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
this._pool = {};
|
||||
}
|
||||
};
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
largeModule('HtmlTextParser');
|
||||
|
||||
var parser = new cc.HtmlTextParser();
|
||||
var parser = new cc._Test.HtmlTextParser();
|
||||
|
||||
test('Basic Test', function() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user