Closed JonnyCodes closed 6 years ago
Whoops, I forgot to mention I'm using StageGL.
Are you manually calling release on the bitmapCache
or are you using the uncache
method from DisplayObject
? The uncache
method should be setting the bitmapCache
property to undefined.
_rectangle
is just a reusable object that gets returned from getBounds
. The idea is to avoid unnecessary object creation and the associated overhead.
I was calling bitmapCache.release
, like a fool! Thanks.
Is the text supposed to get measured every time getBounds
is called or should it be storing _bounds
so when displayObject.getBounds
is called it can return the _rectangle
rather than remeasure the text?
Not automatically. If you look at the description for getBounds
it gives an example for how to stop it recalculating the bounds each time. You can also cache the text and it will use the bounds of the cache instead of measuring the text.
Awesome, thanks for replying so quickly!
On a side note, I'm also a big fan of Grim Fandango.
Been working through some problems getting the bounds of Text objects and caching:
Text.js:253
DisplayObject.js:1145
First of all, I'm not sure what the
_rectangle
object is for, but it seems to be doing the job of the_bounds
object in this case. Because the_bounds
object isn't set at the end ofText.getBounds
when I next calculate the bounds theDisplayObject.getBounds
tries to usebitmapCache
bounds, but if I've just released the cache the returned bounds are{x: 0, y: 0, width: 0, height: 0}
. The bounds of Text objects shouldn't rely on thebitmapCache
bounds. I think when thebitmapCache
is released it should probably nullifythis.bitmapCache
on the display object.The reason I'm releasing the cache is because when I update a Text object the width & height changes and I need to recalculate the size of the
cacheCanvas
. Is there another way to resize thecacheCanvas
that I'm not aware of?