pc.Application类型错误
// Expose prototype methods and create a default tween manager on the application
(function () {// Add pc.Application#addTweenManager methodpc.Application.prototype.addTweenManager = function () {this._tweenManager = new pc.TweenManager(this);this.on("update", function (dt) {this._tweenManager.update(dt);});};// Add pc.Application#tween methodpc.Application.prototype.tween = function (target) {return new pc.Tween(target, this._tweenManager);};// Add pc.Entity#tween methodpc.Entity.prototype.tween = function (target, options) {var tween = this._app.tween(target);tween.entity = this;this.once('destroy', tween.stop, tween);if (options && options.element) {// specifiy a element property to be updatedtween.element = options.element;}return tween;};// Create a default tween manager on the applicationvar application = pc.Application.getApplication();if (application) {application.addTweenManager();}})();
以上代码编辑器调试报错:TypeError: application.addTweenManager is not a function
发布运行则没有问题
测试
var application = pc.Application.getApplication();console.log(application instanceof pc.AppBase)console.log(application instanceof pc.Application)
输出
true
false
经测试,application在编辑器状态下并不是pc.Application类型
调整代码如下:
// Expose prototype methods and create a default tween manager on the application
(function () {// Add pc.Application#addTweenManager methodpc.AppBase.prototype.addTweenManager = function () {this._tweenManager = new pc.TweenManager(this);this.on("update", function (dt) {this._tweenManager.update(dt);});};// Add pc.Application#tween methodpc.AppBase.prototype.tween = function (target) {return new pc.Tween(target, this._tweenManager);};// Add pc.Entity#tween methodpc.Entity.prototype.tween = function (target, options) {var tween = this._app.tween(target);tween.entity = this;this.once('destroy', tween.stop, tween);if (options && options.element) {// specifiy a element property to be updatedtween.element = options.element;}return tween;};// Create a default tween manager on the applicationvar application = pc.Application.getApplication();if (application) {application.addTweenManager();}})();