释放createjs中使用的资源
release used resources in createjs
我有一个Container with multiple Sprite and MovieClip objects displayed on the Stage
, where all the sprites use a 3MB png SpriteSheet。
在某些时候,我加载另一个 SpriteSheet
以显示使用它的不同 Container
。
在反复试验的过程中,我发现设置 Container
的 visible
属性 是不够的,所以我使用了 removeChild(), and also cache(),两者都有帮助适当的帧率。
问题是当我加载更多的容器和 spritesheet 时,帧率偶尔会变得很低。
为了释放已使用的资源,我应该采取任何其他步骤吗?
常见的陷阱是什么?
是的,当我第一次开始在 createJS 中创建应用程序时,我自己遇到了很多性能问题。
如果您的帧率低于应有的水平,请确保缓存每个不是从 Bitmap 创建的对象,因为这些对象不会不断刷新并且不会'消耗性能。例如,Shape 类型的对象不断刷新并且非常耗费性能。
对于没有动画内容的对象,您应该使用以下模式:
var bounds = displayObject.nominalBounds;
displayObject.cache(bounds.x, bounds.y, bounds.width, bounds.height);
这将缓存对象并使其几乎不消耗性能。
此外,当需要摆脱它时,请确保使用类似以下方式处理资产:
//if it was added as a child of a container
displayObject.parent.removeChild(displayObject);
//if it was cached prior
displayObject.uncache();
//when you don't need it anymore, for garbage collection
displayObject = null;
我有一个Container with multiple Sprite and MovieClip objects displayed on the Stage
, where all the sprites use a 3MB png SpriteSheet。
在某些时候,我加载另一个 SpriteSheet
以显示使用它的不同 Container
。
在反复试验的过程中,我发现设置 Container
的 visible
属性 是不够的,所以我使用了 removeChild(), and also cache(),两者都有帮助适当的帧率。
问题是当我加载更多的容器和 spritesheet 时,帧率偶尔会变得很低。
为了释放已使用的资源,我应该采取任何其他步骤吗?
常见的陷阱是什么?
是的,当我第一次开始在 createJS 中创建应用程序时,我自己遇到了很多性能问题。
如果您的帧率低于应有的水平,请确保缓存每个不是从 Bitmap 创建的对象,因为这些对象不会不断刷新并且不会'消耗性能。例如,Shape 类型的对象不断刷新并且非常耗费性能。
对于没有动画内容的对象,您应该使用以下模式:
var bounds = displayObject.nominalBounds;
displayObject.cache(bounds.x, bounds.y, bounds.width, bounds.height);
这将缓存对象并使其几乎不消耗性能。 此外,当需要摆脱它时,请确保使用类似以下方式处理资产:
//if it was added as a child of a container
displayObject.parent.removeChild(displayObject);
//if it was cached prior
displayObject.uncache();
//when you don't need it anymore, for garbage collection
displayObject = null;