EDIT : YES IT IS! (see Bitmap:setTexture() and Bitmap:setTextureRegion() in 2012.8.2+)
I'm working on a super fast text renderer for which I want to use a single texture atlas containing all the font images that I want to use.
The idea is to have a number of "rows" that can contain text strings of different lengths, over time the contents of these row's will be updated and the text will change - currently whenever a row is updated, I create a new Sprite for the row and then add in a series of new Bitmaps (1 per character), however when there are multiple updates you get nasty spikes in the framerate - which I've tracked down to the amount of garbage being generated for all the above memory allocations.
A much better solution would be to "pre-allocate" a bank of bitmaps for each row (for the max number of possible characters per row contents), set them all to be invisible and then instead of re-creating each Bitmap, just simply change the U,V,Width/Height info for each bitmap effectively making it "point" to a different character in the font texture and then making it visible.
But...
The $64,000 question, is.. is it possible to update the texture region that a bitmap points to without having to create a new one. I'm sure it can be with a Shape using the beginPath, moveTo and lineTo functions but that seems overkill and might even be slower than the Bitmap.new()
I initially considered the TileMap:setTile() function but that would only work with a fixed with font.
Anyone (yeah I'm looking you
@Atilim - master of the undocumented functions
) know of a way it can be done on Bitmaps?
As a side note - it'll make bitmap animations an absolute breeze!
PS. If it's NOT possible then prepare to expect a horde of very loud mice *squeaking* this way soon!
Comments
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Likes: OZApps, GregBUG, Mells
Thank you very much ^:)^
Likes: rodri
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Thank you @atilim
http://www.nightspade.com
So, do you mean we could use something like
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
If developers embrace this and put all their anims on a single frame it'll make a really big difference to the app running speed - ESPECIALLY if you reuse objects and don't create any new objects in your EnterFrame function
It'll also be a LOT more efficient than using Movieclips for big anims as you won't have to have a single sprite for each frame - just ONE bitmap that you just change the texture on.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
www.tntengine.com
Waiting for 2012.8.2
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
btw, previously I was planning to add only Bitmap:setTexture() function that accepts both Texture and TextureRegion objects but now there are two functions Bitmap:setTexture() and Bitmap:setTextureRegion() for setting Texture and TextureRegion objects separately.
Likes: atilim
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Bitmap:setTexture() and Bitmap:setTextureRegion() are now documented [ link ].
Bitmap:setTexture(texture)
Sets the texture.Parameters:
texture: (TextureBase)
Bitmap:setTextureRegion(textureRegion)
Sets the texture region.Parameters:
textureRegion: (TextureRegion)
Button = Core.class(Bitmap)
function Button:updateVisualState(state)
if state then
self:setTexture(self.downState) ---here self.downState is now a Texture
else
self:setTexture(self.upState)
end
end
https://sites.google.com/site/xraystudiogame