pubtool4pixi
Version:
Usefultool for PIXI xes project
1,448 lines (1,370 loc) • 90.6 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Timmer = require('./Timmer');
var _polar = require('./polar');
var _polar2 = _interopRequireDefault(_polar);
var _jquery = require('jquery');
var _jquery2 = _interopRequireDefault(_jquery);
var _Observable = require('./Observable');
var _Observable2 = _interopRequireDefault(_Observable);
var _zorderAbility = require('./zorderAbility');
var _zorderAbility2 = _interopRequireDefault(_zorderAbility);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Container = PIXI.Container;
// import { Container, Sprite, Text } from 'pixi.js';
var Sprite = PIXI.Sprite;
var Text = PIXI.Text;
function _moveInterface(obj) {
var fn = obj.scale.set;
obj.scale.set = function (x, y) {
fn.call(obj, x, y);
graphics1.clear();
graphics1.drawRect(-0.5 * obj.width || -100, -0.5 * obj.height || -100, obj.width || 200, obj.height || 200);
};
var graphics1 = new PIXI.Graphics();
graphics1.beginFill(0x000000, 0.2);
graphics1.drawRect(-0.5 * obj.width || -100, -0.5 * obj.height || -100, obj.width || 200, obj.height || 200);
graphics1.interactive = true;
var graphics2 = new PIXI.Graphics();
graphics2.beginFill(0xff0000, 0.2);
graphics2.drawRect(-10, -10, 20, 20);
graphics2.position.set(0.5 * obj.width || -100, -0.5 * obj.height || -100);
graphics2.interactive = true;
graphics2.on("pointerdown", function (e) {
this.basePosition = {};
this.basePosition.x = e.data.global.x;
this.basePosition.y = e.data.global.y;
});
graphics2.on("pointermove", function (e) {
if (this.basePosition) {
var dx = e.data.global.x - this.basePosition.x;
var dy = e.data.global.y - this.basePosition.y;
var p = obj.toLocal(e.data.global, stage);
graphics2.position.set(p.x, p.y);
this.parent.scale.set(this.parent.scale.x + dx * 0.001, this.parent.scale.y - dy * 0.001);
}
});
graphics2.on("pointerup", function (e) {
console.log("scale:", this.parent.scale.x, ",", this.parent.scale.y);
delete this.basePosition;
});
graphics2.on("pointerout", function (e) {
console.log("scale:", this.parent.scale.x, ",", this.parent.scale.y);
delete this.basePosition;
});
graphics1.on("pointerup", function () {
this.allowMove = false;
console.log("Position:", this.parent.x, ",", this.parent.y);
});
obj.addChild(graphics1, graphics2);
var startPoint = void 0;
graphics1.on("pointerdown", function (e) {
this.allowMove = true;
startPoint = obj.toLocal(e.data.global, stage);
});
graphics1.on("pointermove", function (e) {
if (this.allowMove) {
var p = obj.parent.toLocal(e.data.global, stage);
this.parent.position.set(p.x - startPoint.x, p.y - startPoint.y);
}
});
graphics1.on("pointerup", function () {
this.allowMove = false;
console.log("Position:", this.parent.x, ",", this.parent.y);
});
}
function getPoint(p1, p2, a) {
return {
x: p1.x + a * (p2.x - p1.x),
y: p1.y + a * (p2.y - p1.y)
};
}
function FN(aPoint, a) {
var arrLine = [];
for (var i = 1; i < aPoint.length; i++) {
var p1 = aPoint[i - 1];
var p2 = aPoint[i];
arrLine.push([p1, p2]);
}
var Point = [];
for (var _i = 0; _i < arrLine.length; _i++) {
var _p = arrLine[_i][0];
var _p2 = arrLine[_i][1];
Point.push(getPoint(_p, _p2, a));
}
if (Point.length > 1) {
return FN(Point, a);
}
return Point[0];
}
function Fn1(star, end, aBezierPoint, TotalTime) {
var arr = [{ x: 0, y: star }];
arr.push.apply(arr, aBezierPoint);
arr.push({ x: TotalTime, y: end });
return function (time) {
return FN(arr, time / TotalTime);
};
}
var AniFun = {
linear: function linear(t, b, c, d) {
return (c - b) / d * t + b;
},
easeInQuad: function easeInQuad(t, b, c, d) {
return c * (t /= d) * t + b;
},
easeOutQuad: function easeOutQuad(t, b, c, d) {
return -c * (t /= d) * (t - 2) + b;
},
easeInOutQuad: function easeInOutQuad(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t + b;
return -c / 2 * (--t * (t - 2) - 1) + b;
},
easeInCubic: function easeInCubic(t, b, c, d) {
return c * (t /= d) * t * t + b;
},
easeOutCubic: function easeOutCubic(t, b, c, d) {
return c * ((t = t / d - 1) * t * t + 1) + b;
},
easeInOutCubic: function easeInOutCubic(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
return c / 2 * ((t -= 2) * t * t + 2) + b;
},
easeInQuart: function easeInQuart(t, b, c, d) {
return c * (t /= d) * t * t * t + b;
},
easeOutQuart: function easeOutQuart(t, b, c, d) {
return -c * ((t = t / d - 1) * t * t * t - 1) + b;
},
easeInOutQuart: function easeInOutQuart(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
},
easeInQuint: function easeInQuint(t, b, c, d) {
return c * (t /= d) * t * t * t * t + b;
},
easeOutQuint: function easeOutQuint(t, b, c, d) {
return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
},
easeInOutQuint: function easeInOutQuint(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
},
easeInSine: function easeInSine(t, b, c, d) {
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
},
easeOutSine: function easeOutSine(t, b, c, d) {
return c * Math.sin(t / d * (Math.PI / 2)) + b;
},
easeInOutSine: function easeInOutSine(t, b, c, d) {
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
},
easeInExpo: function easeInExpo(t, b, c, d) {
return t == 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
},
easeOutExpo: function easeOutExpo(t, b, c, d) {
return t == d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
},
easeInOutExpo: function easeInOutExpo(t, b, c, d) {
if (t == 0) return b;
if (t == d) return b + c;
if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function easeInCirc(t, b, c, d) {
return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
},
easeOutCirc: function easeOutCirc(t, b, c, d) {
return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
},
easeInOutCirc: function easeInOutCirc(t, b, c, d) {
if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
},
easeInElastic: function easeInElastic(t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) return b;
if ((t /= d) == 1) return b + c;
if (!p) p = d * .3;
if (a < Math.abs(c)) {
a = c;
var s = p / 4;
} else var s = p / (2 * Math.PI) * Math.asin(c / a);
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
},
easeOutElastic: function easeOutElastic(t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) return b;
if ((t /= d) == 1) return b + c;
if (!p) p = d * .3;
if (a < Math.abs(c)) {
a = c;
var s = p / 4;
} else var s = p / (2 * Math.PI) * Math.asin(c / a);
return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
},
easeInOutElastic: function easeInOutElastic(t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) return b;
if ((t /= d / 2) == 2) return b + c;
if (!p) p = d * (.3 * 1.5);
if (a < Math.abs(c)) {
a = c;
var s = p / 4;
} else var s = p / (2 * Math.PI) * Math.asin(c / a);
if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
},
easeInBack: function easeInBack(t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c * (t /= d) * t * ((s + 1) * t - s) + b;
},
easeOutBack: function easeOutBack(t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
},
easeInOutBack: function easeInOutBack(t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
},
easeInBounce: function easeInBounce(t, b, c, d) {
return c - AniFun.easeOutBounce(d - t, 0, c, d) + b;
},
easeOutBounce: function easeOutBounce(t, b, c, d) {
if ((t /= d) < 1 / 2.75) {
return c * (7.5625 * t * t) + b;
} else if (t < 2 / 2.75) {
return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b;
} else if (t < 2.5 / 2.75) {
return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b;
} else {
return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b;
}
},
easeInOutBounce: function easeInOutBounce(t, b, c, d) {
if (t < d / 2) return AniFun.easeInBounce(t * 2, 0, c, d) * .5 + b;
return AniFun.easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
}
};
//t:时间、b:起始位置、c:结束位置、d:总时长
function getAniFun(name, b, c, d) {
var dist = c - b;
return function (t) {
return b + AniFun[name](t, 0, dist, d);
};
}
function playSound(type, isLoop, opt) {
try {
if (type == "bg" || isLoop) {
return PIXI.sound.play("audio_" + type, { loop: true });
} else {
return PIXI.sound.play("audio_" + type, opt);
}
} catch (e) {
try {
return PIXI.sound.play("pub_" + type, opt);
} catch (e) {}
}
}
function stopPlay(type) {
try {
if (type == "bg") {
PIXI.sound.stop("audio_" + type);
} else {
PIXI.sound.stop("audio_" + type);
}
} catch (e) {
try {
PIXI.sound.stop("pub_" + type);
} catch (e) {}
}
}
function getAni(name) {
return new PIXI.spine.Spine(this.res["animation_" + name].spineData);
}
var AniObj = {
getAni: getAni,
getAniFun: getAniFun,
playSound: playSound,
stopPlay: stopPlay,
getBezier: Fn1
};
function clickInterface() {
var _this = this;
var x = 0;
var y = 0;
var name = this.ClickSprite.name;
var isPlaySound = !(this.ClickSprite.isPlaySound === false);
var container = this;
var sprite = new PIXI.Sprite(this.res[name].texture);
var graphics1 = new PIXI.Graphics();
container.allowClick = function () {
return true;
};
graphics1.Sprite = sprite;
graphics1.textureUnClick = this.res[name].texture;
graphics1.textureClick = this.res[name + 'click'] && this.res[name + 'click'].texture || graphics1.textureUnClick;
graphics1.textureOver = this.res[name + 'over'] && this.res[name + 'over'].texture || graphics1.textureUnClick;
sprite.buttonMode = true;
sprite.interactive = true;
graphics1.on("pointerdown", function () {
if (container.allowClick()) {
this.Sprite.texture = this.textureClick;
this._isClick = true;
}
});
graphics1.on("touchend", function () {
this.Sprite.texture = this.textureUnClick;
this._isClick = false;
});
graphics1.on("mouseup", function () {
this.Sprite.texture = this.textureUnClick;
this._isClick = false;
});
graphics1.on("pointermove", function (e) {
if (!container.allowClick()) {
return;
}
if (this._isClick && !graphics1.containsPoint(e.data.global)) {
this.Sprite.texture = this.textureUnClick;
this._isClick = false;
} else if (this._isClick) {
this.Sprite.texture = this.textureClick;
} else if (!this._isClick && graphics1.containsPoint(e.data.global)) {
this.Sprite.texture = this.textureOver;
} else {
this.Sprite.texture = this.textureUnClick;
}
});
if (isPlaySound === true) {
graphics1.on("pointertap", function () {
_this.playSound("click");
});
}
sprite.anchor.set(0, 1);
sprite.x = x;
sprite.y = y + sprite.height;
graphics1.beginFill(0x000000, 0);
graphics1.drawRect(sprite.x, sprite.y - sprite.height, sprite.width, sprite.height);
graphics1.alpha = 1;
graphics1.interactive = true;
graphics1.buttonMode = true;
graphics1.on("pointertap", function () {
_this.fireEvent("onClick");
});
container.on = function (event, fn, context) {
graphics1.on(event, fn, context);
};
container.once = function (event, fn, context) {
graphics1.once(event, fn, context);
};
container.removeListener = function (event, fn, context, once) {
graphics1.removeListener(event, fn, context, once);
};
container._events = graphics1._events;
container.range = graphics1;
container.addChild(sprite, graphics1);
container.Width = sprite.width;
container.Height = sprite.height;
container.resetTexture = function () {
sprite.texture = graphics1.textureUnClick;
graphics1._isClick = false;
};
return container;
}
/**
* @class BaseContainer
* @classdesc 组件基类.
* @param {object} res 资源对象.
* @param {boolean} isPolar 是否采用极坐标定位.
*
* @property {object} parentContainer 组件父容器
*/
var BaseContainer = function (_Container) {
(0, _inherits3.default)(BaseContainer, _Container);
function BaseContainer(res) {
var isPolar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
(0, _classCallCheck3.default)(this, BaseContainer);
var _this2 = (0, _possibleConstructorReturn3.default)(this, (BaseContainer.__proto__ || (0, _getPrototypeOf2.default)(BaseContainer)).call(this));
(0, _Observable2.default)(_this2);
(0, _zorderAbility2.default)(_this2);
_jquery2.default.extend(true, _this2, AniObj);
_this2.res = res;
Object.defineProperty(_this2, "parentContainer", {
get: function get() {
return _this2["_parentContainer"];
},
set: function set(para) {
_this2["_parentContainer"] = para;
/**
* Parent Change Event.
* @memberOf BaseContainer
* @event ParentChange
*/
_this2.fireEvent("ParentChange");
}
});
_this2.addEvent("parentChange", function () {
_this2.isAdd2Parent = false;
});
if (isPolar) {
(0, _polar2.default)(_this2, _this2);
}
_this2.addEvent("created", _this2.BindTool);
return _this2;
}
(0, _createClass3.default)(BaseContainer, [{
key: 'BindTool',
value: function BindTool() {
var _this3 = this;
if (this.ClickSprite) {
clickInterface.call(this);
}
if (this.TrackMode) {
this.addEventOnce("onShow", function () {
_moveInterface(_this3);
});
}
}
}, {
key: 'setParent',
value: function setParent(parent) {
this.parentContainer = parent;
}
}, {
key: 'getSprite',
value: function getSprite() {
return this;
}
}, {
key: 'getParentContainer',
value: function getParentContainer() {
return this.parentContainer;
}
}, {
key: 'add2Parent',
value: function add2Parent(hasMask) {
if (this.isAdd2Parent) {
return;
}
this.isAdd2Parent = true;
if (hasMask) {
if (!this.mask) {
this.mask = new PIXI.Sprite(this.res['mask'].texture);
this.mask.interactive = true;
}
this.parentContainer && this.parentContainer.addChild(this.mask);
}
this.parentContainer && this.parentContainer.addChild(this.getSprite());
}
}, {
key: 'remove2Parent',
value: function remove2Parent() {
if (!this.isAdd2Parent) {
return;
}
this.isAdd2Parent = false;
if (this.mask) {
this.parentContainer && this.parentContainer.removeChild(this.mask);
}
this.parentContainer && this.parentContainer.removeChild(this.getSprite());
}
/**
* show function.
* @function show
* @memberOf BaseContainer
* @param {boolean} Is the container displayed immediately
*/
}, {
key: 'show',
value: function show(isNow) {
var _this4 = this;
if (this.isSlow && !isNow) {
/**
* beforeShow Event.
* @memberOf BaseContainer
* @event beforeShow
* @description Fired before the instance show
*/
this.fireEvent("beforeShow");
this.add2Parent();
this.alpha = 0;
this.showItem(this.getSprite(), function () {
/**
* onShow Event.
* @memberOf BaseContainer
* @event onShow
* @description Fired after the instance show
*/
_this4.fireEvent("onShow");
});
} else {
this.fireEvent("beforeShow");
this.add2Parent();
this.alpha = 1;
this.fireEvent("onShow");
}
this._isShow = true;
return this;
}
/**
* hide function.
* @function hide
* @memberOf BaseContainer
* @param {boolean} Is the container hided immediately
*/
}, {
key: 'hide',
value: function hide(isNow) {
var _this5 = this;
if (this.isSlow && !isNow) {
/**
* beforeHide Event.
* @memberOf BaseContainer
* @event beforeHide
* @description Fired before the instance hide
*/
this.fireEvent("beforeHide");
this.hideItem(this.getSprite(), function () {
_this5.remove2Parent();
/**
* onHide Event.
* @memberOf BaseContainer
* @event onHide
* @description Fired after the instance hide
*/
_this5.fireEvent("onHide");
});
} else {
this.fireEvent("beforeHide");
this.remove2Parent();
this.fireEvent("onHide");
}
this._isShow = false;
return this;
}
}, {
key: 'hideItem',
value: function hideItem(item, cb) {
var TotalTime = this.AniTime || 800;
var fn = getAniFun("linear", item.alpha, 0, TotalTime);
var time = new Date().getTime();
if (item.Iteminterval) {
(0, _Timmer.clearInterval)(item.Iteminterval);
}
var interval = (0, _Timmer.setInterval)(function () {
var dt = new Date().getTime() - time;
item.alpha = fn(dt);
if (dt >= TotalTime) {
(0, _Timmer.clearInterval)(interval);
item.alpha = 0;
item.Iteminterval = null;
cb && cb();
}
});
item.Iteminterval = interval;
}
}, {
key: 'showItem',
value: function showItem(item, cb) {
var TotalTime = this.AniTime || 800;
var fn = getAniFun("linear", item.alpha, 1, TotalTime);
var time = new Date().getTime();
if (item.Iteminterval) {
(0, _Timmer.clearInterval)(item.Iteminterval);
}
var interval = (0, _Timmer.setInterval)(function () {
var dt = new Date().getTime() - time;
item.alpha = fn(dt);
if (dt >= TotalTime) {
item.alpha = 1;
(0, _Timmer.clearInterval)(interval);
item.Iteminterval = null;
cb && cb();
}
});
item.Iteminterval = interval;
}
/**
* @function reset
* @memberOf BaseContainer
* @description remove all event and redo init function
*/
}, {
key: 'reset',
value: function reset() {
this.removeChildren();
this.removeAllListeners();
this.removeAllEvent();
this.init();
}
/**
* @function Destroy
* @memberOf BaseContainer
* @description Destroy the instance
*/
}, {
key: 'Destroy',
value: function Destroy() {
this.parent && this.parent.removeChild(this);
this.destroy && this.destroy();
delete this._Easy.InstanceMap[this.id];
/**
* Destroyed Event.
* @memberOf BaseContainer
* @event Destroyed
* @description Fired when the instance destroyed
*/
this.fireEvent("Destroyed");
}
}]);
return BaseContainer;
}(Container);
var oldSpine = PIXI.spine.Spine;
var stateUpdate = function stateUpdate(delta) {
delta *= this.timeScale;
var tracks = this.tracks;
for (var i = 0, n = tracks.length; i < n; i++) {
var current = tracks[i];
if (current == null) continue;
current.animationLast = current.nextAnimationLast;
current.trackLast = current.nextTrackLast;
var currentDelta = delta * current.timeScale;
if (current.delay > 0) {
current.delay -= currentDelta;
if (current.delay > 0) continue;
currentDelta = -current.delay;
current.delay = 0;
}
var next = current.next;
if (next != null) {
var nextTime = current.trackLast - next.delay;
if (nextTime >= 0) {
next.delay = 0;
next.trackTime = nextTime + delta * next.timeScale;
current.trackTime += currentDelta;
this.setCurrent(i, next, true);
while (next.mixingFrom != null) {
next.mixTime += currentDelta;
next = next.mixingFrom;
}
continue;
}
} else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
tracks[i] = null;
this.queue.end(current);
this.disposeNext(current);
continue;
}
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom;
current.mixingFrom = null;
while (from != null) {
this.queue.end(from);
from = from.mixingFrom;
}
}
if (this.isStop) {
if (this.stopTime !== undefined) {
current.trackTime = this.stopTime;
}
continue;
}
current.trackTime += currentDelta;
}
this.queue.drain();
};
var stateReverseUpdate = function stateReverseUpdate(delta) {
if (this.isStop) {
return;
}
delta *= this.timeScale;
var tracks = this.tracks;
for (var i = 0, n = tracks.length; i < n; i++) {
var current = tracks[i];
if (current == null) continue;
current.animationLast = current.nextAnimationLast;
current.trackLast = current.nextTrackLast;
var currentDelta = delta * current.timeScale;
if (current.delay > 0) {
current.delay -= currentDelta;
if (current.delay > 0) continue;
currentDelta = -current.delay;
current.delay = 0;
}
var next = current.next;
if (next != null) {
var nextTime = current.trackLast - next.delay;
if (nextTime >= 0) {
next.delay = 0;
next.trackTime = nextTime + delta * next.timeScale;
current.trackTime += currentDelta;
this.setCurrent(i, next, true);
while (next.mixingFrom != null) {
next.mixTime += currentDelta;
next = next.mixingFrom;
}
continue;
}
} else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
tracks[i] = null;
this.queue.end(current);
this.disposeNext(current);
continue;
}
if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
var from = current.mixingFrom;
current.mixingFrom = null;
while (from != null) {
this.queue.end(from);
from = from.mixingFrom;
}
}
if (this.isStop) {
if (this.stopTime) {
current.trackTime = this.stopTime;
}
continue;
}
current.trackTime -= currentDelta;
if (current.trackTime <= 0) {
current.trackTime = 0;
}
}
this.queue.drain();
};
function animation(item, bool, x, y, B, s) {
this.state.setAnimation(0, item, bool);
this.x = x;
this.y = y;
this.interactive = B;
this.buttonMode = B;
this.state.timeScale = Math.random() * 0.3 + 1.0;
if (s) {
this.width = this.width / s;
this.height = this.height / s;
}
return this;
}
function addSpine(itemFS1, itemFS2, x, y, t, s, cb) {
var _this6 = this;
this.state.setAnimation(0, itemFS1, false);
this.x = x;
this.y = y;
if (s) {
this.width = this.width / s;
this.height = this.height / s;
}
(0, _Timmer.setTimeout)(function () {
if (_this6.state) {
_this6.state.setAnimation(0, itemFS2, true);
cb && cb();
}
}, this.skeleton.data.animations[t].duration * 1000);
return this;
}
var spineFn = {
setAni: function setAni(name) {
this.continueAni();
this.state.update = stateUpdate;
this.fireEvent("beforeAni");
var track = this.state.setAnimation(0, name, false);
var interval = (0, _Timmer.setInterval)(function () {
me.fireEvent("onAni", [track]);
});
var me = this;
var listeners = {
complete: function complete(track, event) {
(0, _Timmer.clearInterval)(interval);
me.state.removeListener(listeners);
(0, _Timmer.setTimeout)(function () {
me.fireEvent("onAniEnd", [track]);
});
}
};
this.state.addListener(listeners);
return track;
},
setAniLoop: function setAniLoop(name) {
this.continueAni();
this.state.update = stateUpdate;
return this.state.setAnimation(0, name, true);
},
setAniReverse: function setAniReverse(name) {
this.continueAni();
this.state.update = stateReverseUpdate;
this.fireEvent("beforeAni");
var track = this.state.setAnimation(0, name, false);
var interval = (0, _Timmer.setInterval)(function () {
me.fireEvent("onAni");
});
var me = this;
var listeners = {
complete: function complete(track, event) {
(0, _Timmer.clearInterval)(interval);
me.state.removeListener(listeners);
me.fireEvent("onAniEnd", [track]);
}
};
this.state.addListener(listeners);
return track;
},
stopAt: function stopAt(time) {
this.state.isStop = true;
this.state.stopTime = time;
this.state.update = stateUpdate;
},
continueAni: function continueAni() {
this.state.isStop = false;
this.state.stopTime = 0;
}
};
PIXI.spine.Spine = function (SpineData) {
var obj = new oldSpine(SpineData);
(0, _Observable2.default)(obj);
// for(let i in spineFn){
// obj[i] = spineFn[i];
// }
obj.setAni = function (name) {
this.state.continueAni();
this.state.update = stateUpdate;
this.fireEvent("beforeAni");
var track = this.state.setAnimation(0, name, false);
track.trackTime = 0;
var duration = track.animation.duration;
var interval = (0, _Timmer.setInterval)(function () {
obj.fireEvent("onAni", [track]);
if (!track.animation) {
(0, _Timmer.clearInterval)(interval);
track.animation = { duration: 9999 };
obj.fireEvent("onAniEnd", [track]);
}
if (duration - track.trackTime <= 0.01 || !obj.parent) {
(0, _Timmer.clearInterval)(interval);
obj.fireEvent("onAniEnd", [track]);
}
});
return track;
};
obj.setAniLoop = function (name) {
obj.state.continueAni();
obj.state.update = stateUpdate;
return obj.state.setAnimation(0, name, true);
};
obj.setAniReverse = function (name) {
obj.state.continueAni();
obj.state.update = stateReverseUpdate;
var track = obj.state.setAnimation(0, name, false);
track.trackTime = track.animation.duration;
var interval = (0, _Timmer.setInterval)(function () {
obj.fireEvent("onAni", track);
if (track.trackTime === 0) {
(0, _Timmer.clearInterval)(interval);
obj.fireEvent("onAniEnd", track);
}
});
};
obj.state.stopAt = function (time) {
obj.state.isStop = true;
obj.state.stopTime = time;
obj.state.update = stateUpdate;
};
obj.state.continueAni = function () {
obj.state.isStop = false;
obj.state.stopTime = 0;
};
obj.animation = animation;
obj.addspine = addSpine;
_jquery2.default.extend(obj, spineFn);
return obj;
};
/**
* @class Base
* @classdesc Easy基础类.
* @property {object} Map 组件模板映射表
* @property {object} InstanceMap 实例映射表
* @property {object} randomId 随机ID记录器
*/
var Base = function () {
function Base() {
(0, _classCallCheck3.default)(this, Base);
this.Map = {};
this.InstanceMap = {};
this.randomId = 0;
}
/**
* @function define
* @memberOf Base
* @description Define a model
* @param {string} className model's name
* @param {object} prop model's prop
*/
(0, _createClass3.default)(Base, [{
key: 'define',
value: function define(className) {
var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.Map[className]) {
throw new TypeError("This class has been defined");
}
this.Map[className] = prop;
}
/**
* @function create
* @memberOf Base
* @description Create a instance from model
* @param {string} className model's name
* @param {object} extraProp instance's prop
* @return {BaseContainer} Return a instance which designed by model
*/
}, {
key: 'create',
value: function create(className) {
var extraProp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var isBase = arguments[2];
var prop = _jquery2.default.extend(true, {}, this.Map[className], extraProp);
var instance = void 0;
if (prop.extend && prop.extend !== className) {
var extendClassName = prop.extend;
delete prop.extend;
instance = easy.create(extendClassName, prop, true);
delete instance.id;
} else {
instance = new BaseContainer(res, prop.isPolar);
}
_jquery2.default.extend(true, instance, prop, extraProp, { _className: className });
instance._ClassName = className;
this.Map[className].init && this.Map[className].init.call(instance);
// prop.init && prop.init.call(instance);
if (!isBase) {
if (!instance.id) {
instance.id = className;
if (this.InstanceMap[instance.id]) {
instance.id = className + this.randomId;
this.randomId++;
}
} else if (this.InstanceMap[instance.id]) {
throw new Error(instance.id + " has already been declared");
}
this.InstanceMap[instance.id] = instance;
instance.fireEvent("created");
instance._Easy = this;
}
return instance;
}
/**
* @function getCmp
* @memberOf Base
* @description get a created instance
* @param {string} id className or ID
* @return {BaseContainer} A instance
*/
}, {
key: 'getCmp',
value: function getCmp(id) {
return this.InstanceMap[id];
}
}, {
key: 'getClickSprite',
value: function getClickSprite(name) {
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var _this7 = this;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var isPlaySound = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
var container = new PIXI.Container();
var sprite = new PIXI.Sprite(this.res[name].texture);
var graphics1 = new PIXI.Graphics();
graphics1.Sprite = sprite;
graphics1.textureUnClick = this.res[name].texture;
graphics1.textureClick = this.res[name + 'click'] && this.res[name + 'click'].texture || graphics1.textureUnClick;
sprite.buttonMode = true;
sprite.interactive = true;
graphics1.on("pointerdown", function () {
this.Sprite.texture = this.textureClick;
this._isClick = true;
});
graphics1.on("pointerup", function () {
this.Sprite.texture = this.textureUnClick;
this._isClick = false;
});
graphics1.on("pointermove", function (e) {
if (this._isClick && !graphics1.containsPoint(e.data.global)) {
console.log("out");
this.Sprite.texture = this.textureUnClick;
this._isClick = false;
} else if (this._isClick) {
this.Sprite.texture = this.textureClick;
}
});
if (isPlaySound === true) {
graphics1.on("pointertap", function () {
_this7.playSound("click");
});
}
sprite.anchor.set(0, 1);
sprite.x = x;
sprite.y = y + sprite.height;
graphics1.beginFill(0x000000, 0);
graphics1.drawRect(sprite.x, sprite.y - sprite.height, sprite.width, sprite.height);
graphics1.alpha = 1;
graphics1.interactive = true;
graphics1.buttonMode = true;
container.on = function (event, fn, context) {
graphics1.on(event, fn, context);
};
container.once = function (event, fn, context) {
graphics1.once(event, fn, context);
};
container.removeListener = function (event, fn, context, once) {
graphics1.removeListener(event, fn, context, once);
};
container._events = graphics1._events;
container.range = graphics1;
container.addChild(sprite, graphics1);
container.Width = sprite.width;
container.Height = sprite.height;
return container;
}
/**
* @function removeAll
* @memberOf Base
* @description remove all instance except static instance
*/
}, {
key: 'removeAll',
value: function removeAll() {
for (var i in this.InstanceMap) {
if (this.InstanceMap[i].isStatic) {
continue;
}
this.InstanceMap[i].Destroy();
delete this.InstanceMap[i];
}
}
/**
* @function removeAllAndStaitic
* @memberOf Base
* @description remove all instance
*/
}, {
key: 'removeAllAndStaitic',
value: function removeAllAndStaitic() {
for (var i in this.InstanceMap) {
this.InstanceMap[i].Destroy();
delete this.InstanceMap[i];
}
}
/**
* @function destroy
* @memberOf Base
* @description remove instance which has been given
* @param {BaseContainer} instance the instance want to destroy;
*/
}, {
key: 'destroy',
value: function destroy(instance) {
this.InstanceMap[instance.id].Destroy();
delete this.InstanceMap[instance.id];
}
/**
* @function moveInterface
* @memberOf Base
* @description create a movable display object
* @param {PIXI.DisplayObject}
*/
}, {
key: 'moveInterface',
value: function moveInterface(obj) {
_moveInterface(obj);
}
/**
* @function observable
* @memberOf Base
* @description create a observable object
* @param {object}
*/
}, {
key: 'observable',
value: function observable(obj) {
(0, _Observable2.default)(obj);
}
/**
* @function shakeContainer
* @memberOf Base
* @description a shake container animate
* @param stage {object} 摇晃的容器
* @param Num {number} 摇晃次数默认3
* @param dist {number} 摇晃距离
* @param useTime {number} 单次摇晃时间
* @return {Promise}
*/
}, {
key: 'shakeContainer',
value: function shakeContainer(stage) {
var Num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var dist = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
var useTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 100;
return new _promise2.default(function (resolve) {
if (stage._shakeEvent) {
stage._shakeEvent.cancel();
}
stage._shakeEvent = {};
var fn = getAniFun("linear", 0, dist, useTime / 4);
var positive = true;
var isReverse = false;
var time = new Date().getTime();
var count = 0;
var base = stage.x;
stage._shakeEvent.cancel = function () {
(0, _Timmer.clearInterval)(this.twinkleInterval);
stage.x = base;
delete stage._shakeEvent;
};
stage._shakeEvent.twinkleInterval = (0, _Timmer.setInterval)(function () {
var dt = new Date().getTime() - time;
if (dt > useTime / 4) {
isReverse = !isReverse;
count++;
dt = dt % useTime / 4;
positive = parseInt(count % 4 / 2) === 0;
if (count > Num * 4 - 1) {
stage._shakeEvent.cancel();
resolve();
return;
}
time = new Date().getTime();
}
if (isReverse) {
dt = useTime / 4 - dt;
}
if (positive) {
stage.x = base + fn(dt);
} else {
stage.x = base - fn(dt);
}
});
});
}
}]);
return Base;
}();
var easy = new Base();
easy.define("normalBtn", {});
easy.define("muteBtn", {
init: function init() {
var _this8 = this;
var btn = new PIXI.Sprite(this.res["pub_playsound"].texture);
btn.position.set(1920 - 40 - btn.width, 40);
btn.interactive = true;
btn.buttonMode = true;
this.isMute = false;
var allowMove = true;
btn.on("pointertap", function () {
allowMove = false;
if (_this8.isMute) {
btn.texture = _this8.res["pub_playsound"].texture;
PIXI.sound.unmuteAll();
} else {
btn.texture = _this8.res["pub_muteclick"].texture;
PIXI.sound.muteAll();
}
_this8.isMute = !_this8.isMute;
});
// btn.on("pointermove",(e)=>{
// if(btn.containsPoint(e.data.global)){
// if(!allowMove){
// return;
// }
// btn.texture = this.res["pub_muteover"].texture;
// }else{
// allowMove = true;
// if(this.isMute){
// btn.texture = this.res["pub_muteclick"].texture;
// }else{
// btn.texture = this.res["pub_playsound"].texture;
// }
// }
// });
// btn.on("pointerupoutside", ()=>{
// if(this.isMute){
// if(allowMove){
// btn.texture = this.res["pub_muteclick"].texture
// }else{
// btn.texture = this.res["pub_playsound"].texture
// }
// }else{
// btn.texture = this.res["pub_playsound"].texture
// }
// });
// btn.on("pointercancel",()=>{
// if(this.isMute){
// if(allowMove){
// btn.texture = this.res["pub_muteclick"].texture
// }else{
// btn.texture = this.res["pub_playsound"].texture
// }
// }else{
// btn.texture = this.res["pub_playsound"].texture
// }
// });
// btn.on("pointerup", ()=>{
// if(this.isMute){
// if(allowMove){
// btn.texture = this.res["pub_muteclick"].texture
// }else{
// btn.texture = this.res["pub_playsound"].texture
// }
// }else{
// btn.texture = this.res["pub_playsound"].texture
// }
// });
this.addChild(btn);
this.show();
}
});
easy.define("container", {});
function getEasy() {
var easy = new Base();
easy.define("normalBtn", {});
easy.define("muteBtn", {
init: function init() {
var _this9 = this;
var btn = new PIXI.Sprite(this.res["pub_playsound"].texture);
btn.position.set(1920 - 40 - btn.width, 40);
btn.interactive = true;
btn.buttonMode = true;
this.isMute = false;
var allowMove = true;
btn.on("pointertap", function () {
allowMove = false;
if (_this9.isMute) {
btn.texture = _this9.res["pub_playsound"].texture;
PIXI.sound.unmuteAll();
} else {
btn.texture = _this9.res["pub_muteclick"].texture;
PIXI.sound.muteAll();
}
_this9.isMute = !_this9.isMute;
});
btn.on("pointermove", function (e) {
if (btn.containsPoint(e.data.global)) {
if (!allowMove) {
return;
}
btn.texture = _this9.res["pub_muteover"].texture;
} else {
allowMove = true;
if (_this9.isMute) {
btn.texture = _this9.res["pub_muteclick"].texture;
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
}
});
btn.on("pointerupoutside", function () {
if (_this9.isMute) {
if (allowMove) {
btn.texture = _this9.res["pub_muteclick"].texture;
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
});
btn.on("pointercancel", function () {
if (_this9.isMute) {
if (allowMove) {
btn.texture = _this9.res["pub_muteclick"].texture;
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
});
btn.on("pointerup", function () {
if (_this9.isMute) {
if (allowMove) {
btn.texture = _this9.res["pub_muteclick"].texture;
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
} else {
btn.texture = _this9.res["pub_playsound"].texture;
}
});
this.addChild(btn);
this.show();
}
});
easy.define("container", {});
return easy;
}
easy.getNewInstance = getEasy;
var Easy = easy;
/**
* @class BigMath_StarScoreBoard
* @extends BaseContainer
* @classdesc 大数学通用过关结算星星动效
* @property {Number} topicNumber - 游戏题目总数 - 默认值:3
* @property {Number} marginDistance - 星星间隔值 - 默认值:80
* @property {Object} starBgLocation - 背景位置 - 默认值:{x:34,y:36}
* @property {String} StarScoreBoard - 计分板 - 默认值:"image_StarScoreBoard"
* @property {Object} starLocation - 第一颗星星位置 - 默认值:{x:63,y:55}
* @property {String} bgIcon - 默认状态的星星 - 默认值:"image_starIdle"
* @property {String} loseIcon - 失败状态的星星 - 默认值:"image_starLose"
* @property {String} lightSpineName - 成功状态的星星动效名称 - 默认值:"animation_star"
* @property {String} lightAniName - 成功状态的星星播放的动画名称 - 默认值:"star_in"
* @property {String} starPathSpineName - 星星飞的路径动效名称 - 默认值:"animation_starflash"
* @property {String} starPathAniName - 星星飞的路径播放的动画名称 - 默认值:"starflash_in"
* @property {String} starSound - 星星组件的音频配置 - 默认值:"audio_starSound"
*
* @example
* import {Easy} from "pubtool4pixi"
* Easy.create("BigMath_StarScoreBoard",{
* topicNumber : 3,
* marginDistance:80,
* starBgLocation:{
* x:34,y:36
* },
*}).show();
* */
Easy.define("BigMath_StarScoreBoard", {
topicNumber: 3,
marginDistance: 80,
starSound: "audio_starSound",
bgIcon: "image_starIdle",
lightSpineName: "animation_star",
starPathSpineName: "animation_starflash",
lightAniName: "star_in",
starPathAniName: "starflash_in",
loseIcon: "image_starLose",
StarScoreBoard: "image_StarScoreBoard",
starBgLocation: {
x: 34, y: 36
},
starLocation: {
x: 63, y: 55
},
init: function init() {
var to