mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
destroy dynamic atlas texture before loading scene (#2678)
* destroy dynamic atlas texture before loading scene * refine code * refine code
This commit is contained in:
@@ -215,7 +215,7 @@ var Sprite = cc.Class({
|
||||
}
|
||||
}
|
||||
this._spriteFrame = value;
|
||||
if ((lastSprite && lastSprite.getTexture()) !== (value && value.getTexture())) {
|
||||
if ((this._material && this._material._texture) !== (value && value._texture)) {
|
||||
// Drop previous material, because texture have changed
|
||||
this._material = null;
|
||||
this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
|
||||
@@ -522,7 +522,13 @@ var Sprite = cc.Class({
|
||||
},
|
||||
|
||||
_activateMaterial: function () {
|
||||
if (this._material || !this.enabledInHierarchy) return;
|
||||
if (!this.enabledInHierarchy) {
|
||||
return;
|
||||
}
|
||||
if (this._material) {
|
||||
this.node._renderFlag |= RenderFlow.FLAG_RENDER;
|
||||
return;
|
||||
}
|
||||
|
||||
let spriteFrame = this._spriteFrame;
|
||||
// cannot be activated if texture not loaded yet
|
||||
|
||||
@@ -39,7 +39,8 @@ module.exports = {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
if (!sprite._material) {
|
||||
if (!sprite._material || sprite._material._texture !== frame._texture) {
|
||||
sprite._material = null;
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
if (!sprite._material) {
|
||||
if (!sprite._material || sprite._material._texture !== frame._texture) {
|
||||
sprite._material = null;
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ module.exports = {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
if (!sprite._material) {
|
||||
if (!sprite._material || sprite._material._texture !== frame._texture) {
|
||||
sprite._material = null;
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ module.exports = {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
if (!sprite._material) {
|
||||
if (!sprite._material || sprite._material._texture !== frame._texture) {
|
||||
sprite._material = null;
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ module.exports = {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
if (!sprite._material) {
|
||||
if (!sprite._material || sprite._material._texture !== frame._texture) {
|
||||
sprite._material = null;
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ module.exports = {
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
if (!sprite._material) {
|
||||
if (!sprite._material || sprite._material._texture !== frame._texture) {
|
||||
sprite._material = null;
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ let dynamicAtlasManager = {
|
||||
|
||||
if (value) {
|
||||
this.reset();
|
||||
cc.director.on(cc.Director.EVENT_BEFORE_SCENE_LOADING, beforeSceneLoad);
|
||||
cc.director.on(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, beforeSceneLoad);
|
||||
}
|
||||
else {
|
||||
cc.director.off(cc.Director.EVENT_BEFORE_SCENE_LOADING, beforeSceneLoad);
|
||||
cc.director.off(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, beforeSceneLoad);
|
||||
}
|
||||
|
||||
_enabled = value;
|
||||
@@ -127,23 +127,11 @@ let dynamicAtlasManager = {
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Resets all dynamic atlas, and the existing ones are not destroyed, but are reused.
|
||||
* !#zh 重置所有动态图集,已有的动态图集并不会被销毁,而是会被复用。
|
||||
* !#en Resets all dynamic atlas, and the existing ones will be destroyed.
|
||||
* !#zh 重置所有动态图集,已有的动态图集会被销毁。
|
||||
* @method reset
|
||||
*/
|
||||
reset () {
|
||||
for (let i = 0; i <= _atlasIndex; i++) {
|
||||
_atlases[i].reset();
|
||||
}
|
||||
_atlasIndex = -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Releases all dynamic atlas, which are destroyed.
|
||||
* !#zh 释放所有动态图集,这些图集会被销毁掉。
|
||||
* @method releaseAll
|
||||
*/
|
||||
releaseAll () {
|
||||
for (let i = 0, l = _atlases.length; i < l; i++) {
|
||||
_atlases[i].destroy();
|
||||
}
|
||||
@@ -193,10 +181,6 @@ let dynamicAtlasManager = {
|
||||
|
||||
let sprite = node.addComponent(cc.Sprite)
|
||||
sprite.spriteFrame = spriteFrame;
|
||||
// sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
||||
|
||||
// node.width = height;
|
||||
// node.height = height;
|
||||
|
||||
node.parent = content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user