diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index df1ab81ac4..80c36479c6 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -215,6 +215,11 @@ var Sprite = cc.Class({ } } this._spriteFrame = value; + if (lastSprite && lastSprite.getTexture() !== value.getTexture()) { + // Drop previous material, because texture have changed + this._material = null; + this._customMaterial = false; + } this._applySpriteFrame(lastSprite); if (CC_EDITOR) { this.node.emit('spriteframe-changed', this); @@ -496,6 +501,7 @@ var Sprite = cc.Class({ switch (this.type) { case SpriteType.SIMPLE: this._model = SpriteModel.alloc(); + this._model.trimmed = this._isTrimmedMode; break; case SpriteType.SLICED: this._model = SlicedModel.alloc(); @@ -595,9 +601,6 @@ var Sprite = cc.Class({ if (!this.isValid) { return; } - // Drop previous material, because texture have changed - this._material = null; - this._customMaterial = false; // Reattach material to model this._activateModel(); this._applySpriteSize(); @@ -611,7 +614,7 @@ var Sprite = cc.Class({ var spriteFrame = this._spriteFrame; if (spriteFrame) { - if (spriteFrame.textureLoaded()) { + if (spriteFrame.textureLoaded) { this._onTextureLoaded(null); } else { diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index 6499a95133..933221a6bd 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -218,17 +218,18 @@ let _sharedOpts = { mipmap: undefined, images: undefined, image: undefined, + flipY: undefined, premultiplyAlpha: undefined }; function _getSharedOptions () { for (var key in _sharedOpts) { _sharedOpts[key] = undefined; } + _sharedOpts.flipY = false; return _sharedOpts; } var Texture2D = cc.Class({ - name: 'cc.Texture2D', extends: require('../assets/CCRawAsset'), mixins: [EventTarget], @@ -287,7 +288,7 @@ var Texture2D = cc.Class({ */ this.height = 0; - this._texture = new TextureImpl(renderer.device, _emptyOpts); + this._texture = null; }, getImpl () { @@ -454,6 +455,11 @@ var Texture2D = cc.Class({ this.height = this._image.height; let opts = _getSharedOptions(); opts.image = this._image; + if (renderMode.supportWebGL) { + // webgl texture 2d uses images + opts.images = [opts.image]; + } + opts.flipY = false; opts.width = this.width; opts.height = this.height; opts.hasMipmap = this._hasMipmap; @@ -463,7 +469,13 @@ var Texture2D = cc.Class({ opts.magFilter = FilterIndex[this._magFilter]; opts.wrapS = this._wrapS; opts.wrapT = this._wrapT; - this._texture.update(opts); + + if (!this._texture) { + this._texture = new TextureImpl(renderer.device, opts); + } + else { + this._texture.update(opts); + } //dispatch load event to listener. this.loaded = true;