Skip to main content
Inspiring
September 9, 2012
Question

Dynamic textfield creates extreme lag - why??

  • September 9, 2012
  • 1 reply
  • 1327 views

I'm creating an IOS game in AIR where you must shoot birds with certain numbers on them. A new bird spawns every 5 seconds or so, crosses the screen and gets removed after it leaves. I use TweenMax to tween the birds across the screen with a bezier curve. The game is rendered with GPU.

Here's the problem: When I add a dynamic textfield to the "bird" MC (so I can place a number on the bird), it makes the game unplayable: After 20 or so seconds (with maybe 4 birds on screen), the game begins to stutter and eventually halts completely. This is on an iPad 1.

What I've found:

- If I remove the textfield from the "bird" MC, the game runs fine.

- If I put it back, even with static numbers that are never changed by the code, it lags again - so it's not the code that inserts the number that's the problem.

- If I put the textfield in, but leave it empty and never add text, it runs fine, so it's the presence of text in the textfield that's the problem.

I have NO idea what the problem is. I've tried creating the textfield as part of the movieclip AND creating it dynamically at runtime - no difference. I don't embed anything except numbers. I have tried using anti-alias, no anti-alias, device fonts - no difference.´

I have NO idea why the presence/tweening of 4-5 dynamic textfields would create what looks like a huge memory leak. Anyone heard of this?

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
September 9, 2012

After you have changed the number in the movieclip, set it to be cacheAsBitmap = true. Then the GPU should use the bitmap version. As you have it right now it's effectively uploading a new texture every frame.

Inspiring
September 9, 2012

Should the textfield or the parent movieclip or both have cacheToBitmap set to true? I read a bit about it, and it seems that cacheAsBitmap is very limited in its application; for example that it can't be used on elements that are rotated (which I do via my bezier tweening).

Also, if cacheToBitmap is supposed to be used on the textfield - can I only do this if the textfield is created dynamically, or will it also work on a textfield placed in my movieclip in the library?

Colin Holgate
Inspiring
September 9, 2012

You would set the cacheasbitmap on the parent movieclip after making the changes to the text field. If you want to be sure that it gets handled by the GPU you could also set its cacheasbitmapmatrix too.